A method and device for learning MAC address
By identifying the types of received packets and only performing MAC address learning on preset types of packets, the problem of network equipment traffic exceeding the performance upper limit and information quantity upper limit during the MAC address learning process is solved, and packet loss is reduced. and effects of dealing with stress.
Patent Information
- Application Number
- CN202111028241.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-02
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-09-02
AI Technical Summary
During the MAC address learning process of existing network equipment, packet loss may occur when the traffic exceeds the performance upper limit, and the upper limit on the number of MAC address information prevents some information from being recorded, increasing the traffic burden and processing pressure.
By parsing the received message types, only preset types of messages are learned for MAC addresses, avoiding learning for all messages, reducing the processing pressure of network equipment and the number of records of MAC address information.
Without increasing hardware performance and cost, reduce the traffic processed by network equipment, avoid packet loss, reduce the amount of MAC address information that needs to be learned, and improve forwarding efficiency and success rate without increasing the upper limit of the number of MAC address information records. .
Smart Images

Figure CN114125078B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a method and device for learning a MAC address. Background Art
[0002] According to the seven-layer model (Open System Interconnection, OSI) developed by the International Organization for Standardization (ISO), each layer has different identifiers to distinguish different devices and enable peer-to-peer communication. The MAC address belongs to the identifier of the second layer of the data link layer of the model, which identifies a unique device in the data link layer. As a data unit exchanged and transmitted in the network, the message contains the source MAC address and the destination MAC address. When receiving a message, the network device will look up the corresponding output port according to the destination MAC address to forward the message through the output port found. If the network device does not record the correspondence between the destination MAC address and the output port, it will "flood" all ports except the input port, resulting in unnecessary traffic burden.
[0003] In the related technology, when forwarding messages, network devices will record the correspondence between the source MAC address of the message and the input port through MAC address learning, so as to quickly forward the message that needs to be sent to the source MAC address to the correct port. This method does effectively reduce the traffic burden to a certain extent.
[0004] However, the traffic transmitted by the network changes dynamically. When the traffic exceeds the performance limit of MAC address learning of network devices, the MAC addresses of some traffic may not be learned, resulting in packet loss. At the same time, there is an upper limit on the number of MAC address information that network devices can learn. When there are too many MAC address information to be learned, some MAC address information may not be recorded even if the traffic is not large. Summary of the invention
[0005] In view of this, the present application provides a method and device for MAC address learning to address the deficiencies in the related art.
[0006] Specifically, the present application is implemented through the following technical solutions:
[0007] According to a first aspect of an embodiment of the present application, a method for learning a MAC address is provided, which is applied to a network device, and the method includes:
[0008] Parsing the received target message and obtaining corresponding message information, wherein the message information includes a target message type of the target message;
[0009] Determining whether the target message type belongs to a preset message type;
[0010] If the judgment result is yes, MAC address learning is performed for the target message.
[0011] According to a second aspect of an embodiment of the present application, a MAC address learning device is provided, which is applied to a switch device, and the device includes:
[0012] A message parsing module, used to parse the received target message to obtain corresponding message information, wherein the message information includes a target message type of the target message;
[0013] A message type determination module, used to determine whether the target message type is a preset message type;
[0014] The MAC address learning module is used to perform MAC address learning for the target message if the judgment result is yes.
[0015] According to a third aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the steps of the method described in the first aspect are implemented.
[0016] According to a fourth aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method described in the first aspect are implemented.
[0017] In the technical solution provided by the present application, by identifying the type of received messages and only learning MAC addresses for messages of preset types, rather than learning MAC addresses for all messages, the traffic that the network device needs to process can be reduced without improving hardware performance and cost, avoiding traffic exceeding the performance limit of the network device, or reducing packet loss caused by exceeding the performance limit. At the same time, the present application can reduce the MAC addresses that the network device needs to learn, and can reduce the amount of MAC address information that the network device needs to learn without increasing the upper limit of the number of records of MAC address information, avoiding exceeding the above-mentioned upper limit of the number of records, or reducing the amount of MAC address information that cannot be learned due to exceeding the upper limit of the number of records.
[0018] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0020] Figure 1 It is a flowchart of a method for learning a MAC address provided according to an exemplary embodiment of the present application.
[0021] Figure 2 This is a schematic diagram of the MAC address learning principle.
[0022] Figure 3 It is a flowchart of another MAC address learning method provided according to an exemplary embodiment of the present application.
[0023] Figure 4 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present application.
[0024] Figure 5 It is a structural diagram of a MAC address learning device according to an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0025] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0026] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0027] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0028] The present application provides a MAC address learning method based on message type, which is applied to network equipment to illustrate the technical solution of the present application. The technical solution of the present application is described below through specific embodiments:
[0029] Figure 1 is a flow chart of a method for learning a MAC address according to an exemplary embodiment of the present application. Figure 1 As shown, the method may include the following steps:
[0030] S101, parsing a received target message and obtaining corresponding message information, wherein the message information includes a target message type of the target message.
[0031] When a device needs to transmit information to another device, it needs to be forwarded by a network device (such as a switch), and the message received by the network device can be called a target message. The target message type is used to characterize the type of the target message.
[0032] In one embodiment, the original message type of the target message can be obtained by parsing the type field in the target message, and used as the target message type. For example, the message type obtained by parsing the "type" field in the ARP message is "0x0806", and similarly, the message type of the LLDP message is "0x88cc".
[0033] In another embodiment, after parsing the type field in the target message to obtain the original message type of the target message, a preset type identifier that corresponds to the original message type in advance can be further determined, and the preset type identifier is used as the above-mentioned target message type. For example, an FPGA chip is set in the network device, and the chip is formed with a receiving module, a parsing module, and a learning module described below through a burned configuration file. After the receiving module receives the target message from the network device, the parsing module parses the target message to obtain the original message type, and the parsing module further replaces the original message type with the corresponding preset type identifier.
[0034] Among them, there is a one-to-one correspondence between the preset message identifier and the original message type. For example, if the original message type of the above-mentioned ARP message is "0x0806", then the corresponding preset type identifier can be "5'b00001", and if the original message type of the ARP message is "0x88cc", then the corresponding preset type identifier can be "5'b00010", and the corresponding preset type identifiers can be obtained for VLAN, MPLS and other types of message types in the same way. The correspondence between the above-mentioned preset type identifier and the original message type can be pre-recorded in the message relationship correspondence table, and then the parsed original message type can be accurately converted into the corresponding preset type identifier by querying the table.
[0035] The parsing module needs to transmit the message information to the learning module for processing by the learning module, such as MAC address learning, etc. Since the transmission of message information between the parsing module and the learning module consumes certain chip resources, the identification length of the above-mentioned preset type identification can be smaller than the length of the original message type, which is equivalent to data compression of the original message type. This can not only reduce the space occupied when storing message information, but also reduce the data transmission volume when the parsing module sends message information to the learning module, thereby achieving the purpose of improving transmission efficiency.
[0036] S102: Determine whether the target message type belongs to a preset message type.
[0037] The preset message type is a pre-set type of specific message that needs to perform MAC address learning. For example, the preset message type may include one or more of ARP messages, LLDP messages, VLAN messages, MPLS messages, etc. Of course, other types of messages can also be set, and this application does not limit this. Through the above judgment, it can be determined whether MAC address learning is required for the target message: only when the target message type belongs to the preset message type, MAC address learning is required for the target message.
[0038] In one embodiment, the pre-configured message type to be learned is first determined, and the target message type is matched with the message type to be learned. The pre-configured message type to be learned can be analogous to the design logic of a "white list". For example, when the ARP message is set to the pre-configured message type to be learned, other target message types will fail to match the message type to be learned, and MAC address learning cannot be performed. Only the ARP message can be matched successfully and MAC address learning can be performed.
[0039] In another embodiment, the pre-configured message type to be filtered is first determined, and the target message type is matched with the message type to be filtered. The pre-configured message type to be filtered can be analogous to the design logic of a "blacklist". For example, when the LLDP message is used as the message type to be filtered, the LLDP message cannot perform MAC address learning because it successfully matches the message type to be filtered. When other types of messages fail to match the message type to be filtered, MAC address learning can be performed.
[0040] Similar to the preset type identifier above, in one embodiment, a judgment identifier can be used to represent the preset message type. For example, it can be stipulated that when the judgment identifier is "5'b00001", only ARP messages are allowed to pass; when the judgment identifier is "5'b10010", only LLDP and other messages are allowed to pass; when the judgment identifier is "5'b11111", all messages can pass. The advantage of the judgment identifier is that it uses a binary method to represent the preset message type, so that the judgment identifier occupies a small space, has a low maintenance cost and difficulty, and is operable and easy to expand.
[0041] It is easy for a person skilled in the art to think that the length and format of the judgment identifier in the above embodiment can be freely set according to the number of similar messages that need to be judged. For example, an octal representation judgment identifier with a two-byte length can be used, or a binary representation judgment identifier with a six-byte length can be used. The present application does not limit this.
[0042] S103: If the judgment result is yes, then perform MAC address learning for the target message.
[0043] There are some types of messages in the target message (such as TCP, UDP and other IP messages) that do not belong to the protocol messages of the data link layer. Since the MAC address is the main identifier to distinguish the device in the protocol message of the data link layer, and the MAC address learning technology is aimed at the MAC address itself, the IP type message is not prominent in MAC address learning and cannot play its original role. By judging the message type before learning the MAC address of the target message, it is possible to avoid MAC address learning for meaningless types of messages, and use the limited device computing power and memory space for MAC address learning for messages of protocols such as ARP, LLDP, VLAN, MPLS, etc., which helps to improve the forwarding efficiency and success rate of related messages.
[0044] When learning the MAC address of a target message, it is necessary to obtain the MAC address information of the target message, that is, the source MAC address contained in the target message and the input port corresponding to the target message on the network device. The above MAC address information can be obtained by parsing the target message. As mentioned above, the target message can be parsed by the parsing module configured on the FPGA to obtain the MAC address information.
[0045] In one embodiment, the parsing module parses the target message to obtain message information, which includes the target message type and the MAC address information of the target message. After the parsing module sends the message information to the learning module, the learning module can determine whether the target message type in the message information belongs to the preset message type: if so, the MAC address learning operation is started according to the MAC address information in the message information; if not, the MAC address learning operation is not performed. Since the message information includes both the target message type and the MAC address information, as described above, by converting the original message type into a preset type identifier with a shorter length as the target message type, the message information can be minimized, thereby reducing the amount of data transmission between the parsing module and the learning module.
[0046] In another embodiment, the above-mentioned message information only includes the target message type. At this time, the parsing module sends the message information to the learning module, so that the learning module can only judge whether the target message type belongs to the preset message type based on this, and feed back the judgment result to the parsing module: if so, the parsing module further parses the target message to obtain MAC address information, and sends the MAC address information to the learning module for the learning module to perform MAC address learning; if not, the parsing module does not need to further parse the target message, and the learning module will not perform MAC address learning operations on the target message. Since the parsing module will only parse the MAC address information of the target message and transmit it to the learning module when the target message type belongs to the preset message type, instead of parsing and transmitting the MAC address information of the target message in all cases, the processing pressure of the parsing module can be reduced, and the amount of data transmission between the parsing module and the learning module can be reduced.
[0047] Network equipment can refer to Figure 2 The MAC address information of the target message is learned in the manner shown. Figure 2As shown, first, the current MAC address table is assumed to be in the initial state and the content is empty; when the E0 / 2 interface of the switch receives the ARP message sent by device 2, its MAC address "0000:0000:2222" and the interface "E0 / 2" are combined as a MAC address information and saved in the MAC address table. The above-mentioned ARP message can be the target message of this application, and the corresponding MAC address information includes the MAC address "0000:0000:2222" of device 2 and the interface "E0 / 2" on which the switch receives the ARP message, for example, it can be recorded as "0000:0000:2222-E0 / 2". And, the switch will query the MAC address table whether there is corresponding MAC address information based on the target MAC address carried in the message. Obviously, at this time, there is no other MAC address information in the MAC address table except the above-mentioned "0000:0000:2222-E0 / 2". Therefore, the switch sends the message to other devices in the same network segment except device 2, namely device 1, device 3...device N, where N represents the total number of devices in the network segment. Assuming that the target MAC address of the message is the MAC address of device 1 "0000:0000:1111", through flooding operation, after receiving the message, device 1 determines that the target device of the message is the local device based on the target IP, and then performs corresponding processing and response. Other devices will refuse to process the request of the message. If device 1 returns a message to device 2 after processing, that is, the destination MAC address of the message is the MAC address of device 2, because the MAC address information of "0000:0000:2222-E0 / 2" exists in the MAC address table, when the switch receives the message with the destination MAC of 0000.0000.2222 again, it will only forward it from the E0 / 2 interface.
[0048] In one embodiment, if the target message type belongs to a preset message type, it is preliminarily determined that the target message needs to be MAC address-learned. Further, the learned MAC address stored in the memory can be detected to determine whether there is a learned MAC address identical to the target message; if it exists, it is not necessary to repeat the learning; if it does not exist, a remaining pre-allocated memory address is read from the address resource pool and the MAC address information of the target message is written; wherein the address resource pool is used to maintain the pre-allocated memory address for storing the learned MAC address. For example, assuming that a maximum of 64 MAC address information can be stored in the memory, the address resource pool can contain 64 pre-allocated memory addresses when initialized. When a MAC address information needs to be learned, a pre-allocated memory address can be read from the address resource pool, and the learned MAC address information is written to the read pre-allocated memory address, and the read pre-allocated memory address is deleted from the address resource pool, so that 63 pre-allocated memory addresses remain in the address resource pool. When the pre-allocated memory addresses in the address resource pool are reduced to 0, it is impossible to continue to learn new MAC address information. Furthermore, if the MAC address information written to a pre-allocated memory address is deleted, the pre-allocated memory address will be re-added to the address resource pool for re-learning new MAC address information. It can be seen that the pre-allocated memory address can be accurately managed based on the address resource pool, which can ensure that all pre-allocated memory addresses can be read and used, and prevent other memory space from being occupied by MAC address information.
[0049] It is easy for a person skilled in the art to think that the maximum number of MAC address information that can be learned can be determined according to the memory size of the network device, and it is not limited to storing 64 MAC address information. For example, more or less MAC address information can be stored, and this application does not limit this. In other words, the hardware's own conditions will not change the MAC address learning technology itself. At the same time, this application does not limit the implementation method of the address resource pool. If the hardware conditions permit, the technical effect of maintaining the address resource pool can be achieved through a first-in-first-out data buffer (First In First Out, FIFO), or through a linked list, queue and other data structures.
[0050] For the pre-allocated memory address read from the address resource pool, in addition to writing the MAC address information of the target message, a predefined valid value can also be written to the valid state field in the read pre-allocated memory address. For example, the value of the valid state field can be represented by a 1-bit binary value; wherein, when the value is 1, it can be considered as a valid value, indicating that the learned MAC address information has been written into the read pre-allocated memory address, and when the value is 0, it can be considered as an invalid value, indicating that the learned MAC address information has not yet been written into the read pre-allocated memory address. Therefore, according to the value of the valid state field, the learned MAC address information can be accurately identified, which is convenient for counting the number of learned MAC address information, and for quickly screening or reading the learned MAC address information, reducing the difficulty of later maintenance and troubleshooting. For example, after receiving a query request, the network device can determine all pre-allocated memory addresses whose corresponding valid state fields are the said valid values, and display the MAC address information recorded in the determined pre-allocated memory addresses.
[0051] In addition to the valid value, the target message type can also be written into the read pre-allocated memory address. For example, when the message information contains both the target message type and the MAC address information, the message information as a whole can be written into the read pre-allocated memory address. For another example, when the message information only contains the target message type, the message information and the MAC address information can be written into the read pre-allocated memory address respectively. Accordingly, when viewing the learned MAC address information, the MAC address information can be classified and displayed according to the message type, further reducing the difficulty of later maintenance and troubleshooting.
[0052] When writing the learned MAC address information to the pre-allocated memory address read above, the current time (i.e., the time of writing the corresponding MAC address information) can also be written in the pre-allocated memory address as the writing time of the MAC address information of the target message, and used to determine the existence time of the MAC address information of the target message. In the "aging" process of clearing the recorded MAC address information that has existed in the memory for too long, the storage content in each pre-allocated memory address can be aged according to the existence time and the preset aging time. For example, 60 seconds can be set as the aging time, and the writing time of all MAC address information in the memory is read every second, and the existence time of the corresponding MAC address information is obtained by subtracting the writing time from the current time; wherein, if the existence time is greater than 60 seconds, the corresponding address will be cleared, that is, the content written to the memory address is cleared. For example, at the 0th second, the learning module writes the MAC address information A into the memory together with the current writing time. At the 30th second, another MAC address information B is written into the memory in the same way. After 60 seconds, since MAC address information A exists for more than 60 seconds, its memory address is cleared, while MAC address information B still exists for 30 seconds, so it can still be retained in the memory. By storing the write time together with the MAC address information, the long-term occupation of memory space by the learned MAC address information is effectively solved, especially for some MAC address information with low usage rate, the utilization rate of memory space can be improved.
[0053] In addition to periodically aging the learned MAC address information, the heat of the MAC address information can also be considered. For example, after writing the MAC address information of target message A to a pre-allocated memory address, if the MAC address information of target message B is received and is the same as the MAC address information of target message A, then although the network device does not need to re-learn the MAC address information of target message B, it can update the writing time of the previously learned MAC address information so that the aging cycle of the MAC address information can be updated. Assuming that the aging time is still 60s, if target message B is received at 30s, then the writing time of the corresponding MAC address information can be updated so that the MAC address information will not age at 60s, but may only age at 90s. Then, if the target message corresponding to the same MAC address information can be received before aging every time, it means that the heat of the MAC address information is very high, and thus the MAC address information can always not age.
[0054] It can be seen from the above embodiments that the MAC address learning technical solution in the present application, under the premise of ensuring that the performance and cost of the hardware equipment do not need to be improved, performs MAC address learning on specific types of messages, so that the traffic containing most of the remaining messages that do not conform to the specific type is filtered. This solves the problem of packet loss caused by the inability of the MAC address learning module to process and learn the MAC addresses of each message in a timely manner when the network device receives too much traffic. At the same time, the present application can reduce the MAC addresses that the network device needs to learn, and can reduce the number of MAC address information that the network device needs to learn without increasing the upper limit of the number of records of MAC address information, avoiding exceeding the above-mentioned upper limit of the number of records, or reducing the number of MAC address information that cannot be learned due to exceeding the upper limit of the number of records. In addition, by maintaining and troubleshooting problems related to the MAC address table according to the type of message, the subsequent manpower and time costs for technicians in this field are reduced, and the work efficiency is improved.
[0055] The technical solution of the present application is described in detail below through an embodiment involving an FPGA chip in a switch performing MAC address learning on received messages.
[0056] In fact, the above embodiments have involved a series of operations of MAC address learning by the receiving module, parsing module and learning module obtained by writing the FPGA chip program. The FPGA chip itself is a product further developed on the basis of programmable devices such as PAL, GAL, CPLD, etc. It appears as a semi-custom circuit in the field of application-specific integrated circuits (ASICs), which not only solves the shortcomings of custom circuits, but also overcomes the shortcomings of the limited number of gate circuits of the original programmable devices.
[0057] The process of the FPGA chip in the switch learning the MAC address of the received target message is as follows: Figure 3 As shown, Figure 3 is a flowchart of another MAC address learning method provided according to an exemplary embodiment of the present application, referring to Figure 3 , the method may include the following steps:
[0058] S301, parse the incoming target message, obtain a 5-bit preset message type identifier corresponding to the original message type and 96-bit MAC address information in the message as message information.
[0059] First, for the FPGA chip in this embodiment, we assume that the FPGA chip is formed with a receiving module, a parsing module and a learning module through a burned configuration file.
[0060] In one embodiment, after receiving the target message, the receiving module parses the target message through the parsing module to obtain the original message type. The parsing module reads a pre-established message relationship correspondence table, which is used to record the correspondence between the original message type and the preset type identifier. Therefore, assuming that the target message is an ARP message, that is, the original message type is "0x0806", the parsing module can obtain the corresponding preset type identifier "5'b00001" according to the above message relationship correspondence table, and combine the 5-bit preset type identifier and the 96-bit MAC address information to form a total length of 101 bits of message information.
[0061] S302, determining whether the message information conforms to a preset message type consisting of 5 bits.
[0062] In one embodiment, similar to the message type correspondence table, one or more judgment identifiers with a length of 5 bits are used to represent the message type that needs to learn the MAC address. Specifically, it is assumed that the judgment identifier is preset to 5'b00011, that is, only ARP and LLDP type messages are allowed to learn the MAC address. At the same time, for messages that meet the judgment identifier requirements and finally pass, they can formally enter the learning module. If not passed, execute S310.
[0063] S303, polling 64 memories storing MAC address information to determine whether the MAC address information of the target message is repeated with the MAC address information stored in the memory.
[0064] In one embodiment, when the message information enters the learning module, the learning module polls the 64 memory addresses in the FPGA chip for storing MAC addresses to detect whether there is content consistent with the MAC address information of the message information. If not, S304 is executed. If the same MAC address information exists, S310 is executed.
[0065] S304, read the corresponding pre-allocated memory address with a remaining depth of 64 and a bit width of 112 bits from the address resource pool storing 64 values 0-63.
[0066] In one embodiment, after the FPGA chip is powered on, its learning module initializes the address resource pool on the chip. The address resource pool can be implemented by a data buffer on the FPGA, such as a FIFO, in which 64 values 0-63 can be written, and these 64 values represent 64 pre-allocated memory addresses in the memory, and these pre-allocated memory addresses are respectively used to record the learned 64 groups of MAC address information.
[0067] S305, store the 96-bit MAC address of the target message, the 5-bit message type identifier, the 10-bit cache time, and the 1-bit valid bit into the read pre-allocated memory address.
[0068] In one embodiment, after obtaining the remaining pre-allocated address, the learning module writes the MAC address, the message type tag, the current time, and a total of 112 bits of valid bits into the above address.
[0069] S306, according to the received query request, search the 64 addresses in the memory in turn, and display the contents of all addresses whose valid bits are 1 according to the message type.
[0070] In one embodiment, if the user needs to detect the currently learned MAC address information, the 64 addresses in the memory can be read in a round-robin manner, and the address contents with all valid bits being 1 in the memory can be displayed according to the message type.
[0071] S307: Abandon learning the MAC address of the target message.
[0072] Specifically, when the target message does not completely meet the specified MAC address learning conditions, the switch will filter the traffic carrying the target message, that is, give up MAC address learning for the target message.
[0073] Through the above embodiments, it can be known that after receiving the target message through the receiving module, the FPAG chip in the switch (i.e., the network device) uses the parsing module in the chip to compress and integrate the MAC address and message type in the target message into message information. Secondly, it is determined whether the message information belongs to the message type that the user needs to perform targeted MAC address learning according to the message type. If so, the address resource pool and memory address in the FPGA chip will be used to write the MAC address information and other message information into the pre-allocated memory address through the learning module. After the MAC address learning process of the target message is completed normally, the user needs to check whether the MAC address information currently learned in the memory belongs to some data link layer-based protocol messages (such as ARP, LLDP messages), and then retrieve the MAC address learning information that is meaningful to the user according to the message type and valid bits. Through the above embodiments, one or more of ARP, LLDP, VLAN and MPLS messages can be allowed to learn mac addresses, which means that the remaining traffic is filtered out during the MAC address learning process, thereby effectively reducing the traffic burden that the learning module needs to handle and improving the efficiency of MAC address learning; at the same time, because the sending interval of ARP and LLDP messages is very long, the performance bottleneck of the learning module will not be reached, thereby not causing the omission of MAC address statistics and thus causing packet loss; further, through the solution of this application, the staff in this field can view the technical effect of the learned MAC according to the message type, so as to save unnecessary time and manpower costs caused in the process of maintaining and troubleshooting the MAC address table, and further improve its maintenance and maintenance efficiency.
[0074] Figure 4 is a schematic structural diagram of a network device according to an exemplary embodiment of the present application. Figure 4 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and of course may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a MAC address learning device at the logical level. Of course, in addition to software implementations, this application does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0075] Corresponding to the above-mentioned embodiment of the MAC address learning method, the present application also provides an embodiment of a MAC address learning device.
[0076] Please refer to Figure 5 , Figure 5is a block diagram of a MAC address learning device according to an exemplary embodiment of the present application. Figure 5 As shown, in a software implementation, the MAC address learning device may include:
[0077] A message parsing unit 510, parses the received target message and obtains corresponding message information, wherein the message information includes a target message type of the target message;
[0078] A message type determination unit 520 is configured to determine whether the target message type belongs to a preset message type;
[0079] The MAC address learning unit 530 performs MAC address learning for the target message if the judgment result is yes.
[0080] Optionally, an FPGA chip is provided in the electronic device, and the FPGA chip forms a receiving module, a parsing module and a learning module through a burned configuration file; the message information also includes the MAC address information of the target message; the message parsing unit 510 is specifically used to: parse the target message received by the receiving module through the parsing module to obtain the message information; the message type judgment unit 520 is specifically used to: obtain the message information generated by the parsing module through the learning module, and judge whether the target message type contained in the message information belongs to the preset message type; the MAC address learning unit 530 is specifically used to: when the judgment result is yes, perform MAC address learning on the MAC address information contained in the message information through the learning module.
[0081] Optionally, the message parsing unit 510 is specifically used to: parse the target message to obtain the original message type; determine a preset type identifier corresponding to the original message type as the target message type; wherein the length of the preset type identifier is less than the length of the original message type.
[0082] Optionally, the MAC address learning unit 530 is specifically used to: detect the learned MAC addresses stored in the memory to determine whether there is a learned MAC address that is the same as the target message; if not, read a remaining pre-allocated memory address from the address resource pool and write the MAC address information of the target message; wherein the address resource pool is used to maintain pre-allocated memory addresses for storing learned MAC addresses.
[0083] Optionally, the device further comprises:
[0084] The valid value writing unit 540 writes a predefined valid value into the valid status field in the read pre-allocated memory address to indicate that the learned MAC address information has been written into the read pre-allocated memory address.
[0085] The information display unit 550, in response to the received query request, determines all pre-allocated memory addresses whose corresponding valid status fields are the valid values, and displays the MAC address information recorded in the determined pre-allocated memory addresses.
[0086] Optionally, the device further includes: a type writing unit 560, configured to write the target message type into the read pre-allocated memory address.
[0087] The information display unit 550 is specifically used to classify and display the MAC address information recorded in the determined pre-allocated memory address according to the message type.
[0088] Optionally, the device further comprises:
[0089] The time writing unit 570 writes the current time into the read pre-allocated memory address to determine the corresponding existence duration.
[0090] The aging management unit 580 performs aging management on the storage content in the read pre-allocated memory address according to the existence time and a preset aging time.
[0091] The embodiments of the subject matter and functional operations described in this specification may be implemented in the following: digital electronic circuits, tangibly embodied computer software or firmware, computer hardware including the structures disclosed in this specification and their structural equivalents, or a combination of one or more of them. The embodiments of the subject matter described in this specification may be implemented as one or more computer programs, i.e., one or more modules in computer program instructions encoded on a tangible non-temporary program carrier to be executed by a data processing device or to control the operation of the data processing device. Alternatively or additionally, the program instructions may be encoded on an artificially generated propagation signal, such as a machine-generated electrical, optical or electromagnetic signal, which is generated to encode information and transmit it to a suitable receiver device for execution by a data processing device. The computer storage medium may be a machine-readable storage device, a machine-readable storage substrate, a random or serial access memory device, or a combination of one or more of them.
[0092] The processes and logic flows described in this specification can be performed by one or more programmable computers executing one or more computer programs to perform corresponding functions by operating on input data and generating output. The processes and logic flows can also be performed by special purpose logic circuits, such as FPGAs (field programmable gate arrays) or ASICs (application-specific integrated circuits), and the apparatus can also be implemented as special purpose logic circuits.
[0093] Computers suitable for executing computer programs include, for example, general and / or special microprocessors, or any other type of central processing unit. Typically, the central processing unit will receive instructions and data from a read-only memory and / or a random access memory. The basic components of a computer include a central processing unit for implementing or executing instructions and one or more memory devices for storing instructions and data. Typically, the computer will also include one or more large-capacity storage devices for storing data, such as magnetic disks, magneto-optical disks, or optical disks, or the computer will be operably coupled to this large-capacity storage device to receive data from it or to transmit data to it, or both. However, the computer does not necessarily have such a device. In addition, the computer can be embedded in another device, such as a mobile phone, a personal digital assistant (PDA), a mobile audio or video player, a game console, a global positioning system (GPS) receiver, or a portable storage device such as a universal serial bus (USB) flash drive, to name a few.
[0094] Computer readable media suitable for storing computer program instructions and data include all forms of non-volatile memory, media and memory devices, including, for example, semiconductor memory devices (e.g., EPROM, EEPROM and flash memory devices), magnetic disks (e.g., internal hard disks or removable disks), magneto-optical disks, and CD ROM and DVD-ROM disks. The processor and memory may be supplemented by, or incorporated in, special purpose logic circuitry.
[0095] Although this specification includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of protection claimed, but are mainly used to describe the features of the specific embodiments of specific inventions. Certain features described in multiple embodiments in this specification may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in multiple embodiments or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claim protection, one or more features from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.
[0096] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or requiring that all illustrated operations be performed to achieve the desired results. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system modules and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into multiple software products.
[0097] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. In addition, the processing depicted in the accompanying drawings does not necessarily require the specific order or sequential order shown to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous. The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A method for learning a MAC address, characterized in that: Applied to a network device, the method comprises: Parsing the received target message and obtaining corresponding message information, wherein the message information includes a target message type of the target message; Determine whether the target message type belongs to a preset message type; If the judgment result is yes, then perform MAC address learning for the target message; The MAC address learning for the target message includes: detecting the learned MAC address information stored in the memory to determine whether there is the same learned MAC address information as the target message; if not, reading a remaining pre-allocated memory address from the address resource pool and writing the MAC address information of the target message; wherein the address resource pool is used to maintain the pre-allocated memory address for storing the learned MAC address information; Writing a predefined valid value to the valid status field in the read pre-allocated memory address to indicate that the learned MAC address information has been written into the read pre-allocated memory address; In response to the received query request, all pre-allocated memory addresses whose corresponding valid status fields are the valid values are determined, and the MAC address information recorded in the determined pre-allocated memory addresses is displayed.
2. The method according to claim 1, characterized in that The network device is provided with an FPGA chip, and the FPGA chip forms a receiving module, a parsing module and a learning module through a burned configuration file; the message information also includes the MAC address information of the target message; The parsing of the received target message comprises: parsing the target message received by the receiving module by the parsing module to obtain the message information; The determining whether the target message type belongs to a preset message type comprises: acquiring the message information generated by the parsing module through the learning module, and determining whether the target message type contained in the message information belongs to the preset message type; The performing MAC address learning for the target message includes: when the judgment result is yes, performing MAC address learning on the MAC address information contained in the message information by the learning module.
3. The method according to claim 1, characterized in that The obtaining of corresponding message information includes: Parsing the target message to obtain the original message type; Determine a preset type identifier corresponding to the original message type as the target message type; wherein the length of the preset type identifier is smaller than the length of the original message type.
4. The method according to claim 1, characterized in that: The method further comprises: Writing the target message type into the read pre-allocated memory address; The displaying of the MAC address information recorded in the determined pre-allocated memory address includes: classifying and displaying the MAC address information recorded in the determined pre-allocated memory address according to the message type.
5. The method according to claim 1, characterized in that The method further comprises: Write the current time into the pre-allocated memory address read to determine the corresponding existence duration; Aging management is performed on the storage content in the read pre-allocated memory address according to the existence time and the preset aging time.
6. A device for learning a MAC address, characterized in that: Applied in a network device, the device comprises: A message parsing unit, used to parse the received target message to obtain corresponding message information, wherein the message information includes a target message type of the target message; A message type determination unit, used to determine whether the target message type is a preset message type; A MAC address learning unit, configured to perform MAC address learning for the target message if the judgment result is yes; The MAC address learning unit is specifically used to: detect the learned MAC address information stored in the memory to determine whether there is learned MAC address information identical to the target message; if not, read a remaining pre-allocated memory address from the address resource pool and write the MAC address information of the target message; wherein the address resource pool is used to maintain the pre-allocated memory address for storing the learned MAC address information; The device also includes: A valid value writing unit writes a predefined valid value into the valid status field in the read pre-allocated memory address to indicate that the learned MAC address information has been written into the read pre-allocated memory address; The information display unit, in response to the received query request, determines all pre-allocated memory addresses whose corresponding valid status fields are the valid values, and displays the MAC address information recorded in the determined pre-allocated memory addresses.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 5 are implemented.
