Command execution method and device of unmanaged switch and storage medium

By constructing a hierarchical command-line system and using linked list matching technology, the problem of excessive memory usage during CLI command execution on unmanaged switches was solved, achieving low memory consumption and efficient human-computer interaction.

CN120935015AActive Publication Date: 2025-11-11SHENZHEN SCODENO TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511448632.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-11
Publication Date
2025-11-11
Estimated Expiration
2045-10-11

AI Technical Summary

Technical Problem

The excessive memory consumption of CLI command execution on unmanaged switches can cause system crashes, and existing solutions cannot effectively address the memory limitation issue.

Method used

By constructing a hierarchical command-line system, using a preset segmentation algorithm and linked list matching technology, CLI commands are sequence-segmented and matched one by one to generate execution results, which are then output via serial port. This reduces the space occupied by child nodes and the complexity of linked list retrieval, achieving low memory consumption.

Benefits of technology

It enables low-memory CLI command execution on resource-constrained unmanaged switches, improving human-computer interaction efficiency and solving the system crash problem caused by excessive memory usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120935015A_ABST
    Figure CN120935015A_ABST
Patent Text Reader

Abstract

The invention relates to the field of embedded interaction, and discloses a command execution method and device of an unmanaged switch and a storage medium. The method comprises the following steps: receiving CLI command data input by a user; performing sequence segmentation processing on the CLI command data to obtain a sequence token set; according to a chain table of a preset root node, performing matching processing on the sequence token to obtain a matching result; when the matching result is qualified, moving to a child node corresponding to the matching result, and judging whether the sequence of the sequence token is a tail sequence of the sequence token set or not; when the sequence is not the tail sequence, the child nodes corresponding to the matching result are written into the matching node set, and the next sequence token is read; and when the sequence is a tail sequence, binding an execution function based on the matching node set, and generating an execution result based on the execution function. In the embodiment of the invention, the child node command occupying a low space is matched through the CLI command, so that low memory consumption of CLI command execution is realized, and the man-machine interaction efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded interaction, and more particularly to a command execution method, device, and storage medium for an unmanaged switch. Background Technology

[0002] An unmanaged switch is a plug-and-play Ethernet switching device that primarily performs basic data link layer forwarding. It has pre-defined default parameters and automatically learns MAC addresses and establishes a port-to-MAC address mapping table upon power-up. It then forwards data frames to the corresponding ports according to the address table, enabling interconnection between terminal devices.

[0003] Traditional unmanaged switches rely on physical indicator lights (LEDs), requiring engineers to deduce device operation by combining the status of multiple isolated indicator lights. There is a significant conflict between the resources and functionality of unmanaged switches; existing command-line solutions (such as CLI libraries) consume more than 10KB of RAM, far exceeding the 4KB memory limit of unmanaged switches. Forcing a migration to such a solution could lead to system crashes. Therefore, a new technology is needed to address the excessive memory consumption of CLI command execution in unmanaged switches. Summary of the Invention

[0004] The main objective of this invention is to solve the technical problem of excessive memory consumption in CLI command execution on unmanaged switches.

[0005] The first aspect of the present invention provides a command execution method for an unmanaged switch, the command execution method for the unmanaged switch comprising: Receive CLI command data input by the user; According to the preset segmentation algorithm, the CLI command data is processed by sequence segmentation to obtain a sequence token set, and the sequence tokens in the sequence token set are read. The sequence tokens are matched according to the linked list of the preset root node to obtain the matching result; When the matching result is qualified, move to the child node corresponding to the matching result and determine whether the sequence of the sequence token is the tail sequence of the sequence token set; If the sequence is not the tail sequence of the sequence token set, the child node corresponding to the matching result is written into the matching node set, and the sequence token of the next sequence in the sequence token set is read. When it is the tail sequence of the sequence token set, the execution function is bound based on the matching node set, and the execution result is generated based on the execution function.

[0006] Optionally, in a first implementation of the first aspect of the present invention, before the step of receiving CLI command data input by the user, the method further includes: Create a root node and set the node type of the child nodes in the root node, wherein the node type includes: GROUP type and ACTION type; When the node type is GROUP, the attributes of the child node are set, and the child node is attached to the root node; When the node type is ACTION, the execution function of the child node mapping is set, and the child node is mounted to the root node.

[0007] Optionally, in a second implementation of the first aspect of the present invention, the step of binding the execution function based on the matching node set includes: Determine whether the node type of the tail sequence node in the matching node set is ACTION type; When it is of type ACTION, the execution function of the tail sequence node mapping in the matching node set is bound; When it is not of type ACTION, an error message indicating an incomplete command is sent to the preset management serial port.

[0008] Optionally, in a third implementation of the first aspect of the present invention, all ACTION type child nodes corresponding to the root node are stored in a preset memory as constants.

[0009] Optionally, in a fourth implementation of the first aspect of the present invention, after the step of generating the execution result based on the execution function, the method further includes: The execution results are sent to the host computer via a preset management serial port or a USB-to-TTL cable.

[0010] Optionally, in a fifth implementation of the first aspect of the present invention, the step of sending the execution result to the host computer via a preset management serial port or a USB-to-TTL cable includes: The execution result is inserted into the ANSI control code to obtain the colored execution result; The coloring execution results are sent to the host computer via a preset management serial port or a USB-to-TTL cable.

[0011] Optionally, in a sixth implementation of the first aspect of the present invention, after the step of matching the sequence tokens according to the linked list of the preset root node to obtain a matching result, the method further includes: If the matching result is unqualified, an error message for an unknown command is sent to the preset management serial port.

[0012] Optionally, in the seventh implementation of the first aspect of the present invention, after the step of receiving CLI command data input by the user, and before the step of performing sequence segmentation processing on the CLI command data according to a preset segmentation algorithm to obtain a sequence token set, the method further includes: Receive correction instructions from the user; According to the correction instruction, the CLI command data is adjusted to obtain corrected CLI command data, and the corrected CLI command data is assigned to the CLI command data.

[0013] A second aspect of the present invention provides a command execution device for an unmanaged switch, comprising: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected via a line; the at least one processor invokes the instructions in the memory to cause the command execution device for the unmanaged switch to execute the aforementioned command execution method for an unmanaged switch.

[0014] A third aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the command execution method of the unmanaged switch described above.

[0015] In this embodiment of the invention, command-line operations are performed on resource-constrained unmanaged switches. A basic command tree is constructed, and the linked list is traversed from the root node. The user's CLI commands are broken down and matched one by one until a CLI command input by the user is matched. The bound execution function is then executed, and the execution result is output to the screen via a serial port. By leveraging the small space occupied by child node commands and the low retrieval complexity (O(n)) of a single-linked list, low memory consumption for CLI command execution is achieved, improving human-computer interaction efficiency and solving the technical problem of excessive memory consumption for CLI command execution in unmanaged switches. Attached Figure Description

[0016] Figure 1 This is a schematic diagram of an embodiment of the command execution method for an unmanaged switch in this invention. Figure 2 This is a schematic diagram of a specific embodiment prior to step 101 of the command execution method for an unmanaged switch in this invention. Figure 3 This is a schematic diagram of a specific embodiment of the 106 steps of the command execution method for an unmanaged switch in this invention. Figure 4 This is a schematic diagram of an embodiment of a command execution device for an unmanaged switch in this invention. Detailed Implementation

[0017] This invention provides a command execution method, device, and storage medium for an unmanaged switch.

[0018] The embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While some embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the accompanying drawings and embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the present invention.

[0019] In the description of the embodiments disclosed in this invention, the term "comprising" and similar terms should be understood as open-ended inclusion, i.e., "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc., may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0020] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 One embodiment of the command execution method for an unmanaged switch in this invention includes: 101. Receive CLI command data input by the user; In this embodiment, CLI command data is text instructions, which are entered one by one via the keyboard. Based on the Shell / parser, the input string is translated into system calls or hardware operations.

[0021] This invention designs a layered command-line system that focuses on status monitoring and debugging information display, without involving configuration functions. The system consists of three layers: 1. Application Layer (CLI Interaction): Responsible for inputting and parsing CLI commands, and formatting the output of execution results.

[0022] 2. Abstraction layer (command management): Constructs a command tree, performs multi-level command matching, and outputs the command matching results.

[0023] 3. Driver layer (hardware adaptation): Through a fixed output stack buffer, without heap space allocation, the output is sent to the PC terminal via serial port, and the PC terminal can view the execution results.

[0024] For details, please refer to Figure 2 , Figure 2 This is a schematic diagram of a specific embodiment prior to step 101 of the command execution method for an unmanaged switch in this invention. The specific implementation methods prior to step 101 include the following: 1011. Create a root node and set the node type of the child nodes in the root node, wherein the node type includes: GROUP type and ACTION type; 1012. When the node type is GROUP, the attributes of the child node are set, and the child node is attached to the root node. 1013. When the node type is ACTION, the execution function of the child node mapping is set, and the child node is mounted to the root node.

[0025] Steps 1011-1013 create the root node, set the node types of child nodes under the root node, and statically construct the basic command tree, supporting the show series of commands. When the node type is GROUP, GROUP represents structural information such as range / nesting / priority, does not generate any bytecode / machine code / IR instructions, has zero runtime overhead, and has more than or equal to one child node. The attributes of child nodes are set, and child nodes are attached to the node tree of the root node. GROUP type child nodes will subsequently have more child nodes.

[0026] When the node type is ACTION, the ACTION type represents behavioral information such as operation, control, and side effects. It sets the execution function of the child node mapping and attaches the child node to the last leaf node of the root node's node tree. Child nodes of ACTION type will not have any subsequent child nodes.

[0027] Register all child nodes of type GROUP and ACTION to the parent command group, and build a node tree based on the root node according to the parent-child relationship.

[0028] Specifically, all ACTION type child nodes corresponding to the root node are stored in a preset memory as constants. This is solidified during the compilation phase, generating a command array. The command tree structure is solidified during compilation via pre-compilation macros. ACTION type child nodes are stored in the preset memory as constants, and the space occupied by ACTION type child nodes is small; 50 nodes occupy only 1.2KB of storage.

[0029] 102. According to the preset segmentation algorithm, the CLI command data is processed by sequence segmentation to obtain a sequence token set, and the sequence tokens in the sequence token set are read. In this embodiment, the segmentation algorithm can perform sequence segmentation processing on CLI command data based on spaces, set characters, etc., and establish a sequence token set according to the original CLI command data. For example, if the input CLI command data is "show port status", the segmented sequence token set is ['show', 'port', 'status']. Then, the algorithm starts to traverse and read the sequence tokens in the sequence token set.

[0030] Furthermore, after step 101 and before step 102, the following specific implementation methods are also included: 1021. Receive the user's correction command; 1022. According to the correction instruction, adjust the CLI command data to obtain corrected CLI command data, and assign the corrected CLI command data to the CLI command data.

[0031] In steps 1021-1022, the user's backspace key input is received in real time for correction. Based on the correction instruction, the CLI command data is adjusted to generate corrected CLI command data. Then, the corrected CLI command data is reassigned to the original CLI command data for subsequent processing. For example, if A is the CLI command data, and its original value is m, it is adjusted to n by the correction instruction, and then n is assigned to A, resulting in A being n.

[0032] 103. Based on the linked list of the preset root node, perform matching processing on the sequence token to obtain the matching result; In this embodiment, the reading process proceeds in sequence, for example, ['show', 'port', 'status'] reads the sequence tokens of 'show', 'port', and 'status' in that order. Based on the linked list of the root node, the read sequence tokens are matched to generate a matching result.

[0033] Specifically, following step 103, the following specific implementation methods are also included: 1031. When the matching result is unqualified, an error message for an unknown command is sent to the preset management serial port.

[0034] In step 1031, if the matching structure is invalid, the sequence token is not registered in the root node's linked list. An error message for an unknown command is sent to the preset management serial port, and the administrator analyzes whether the CLI command data was entered incorrectly.

[0035] 104. When the matching result is qualified, move to the child node corresponding to the matching result and determine whether the sequence of the sequence token is the tail sequence of the sequence token set; In this embodiment, when the matching result is qualified, it means that the sequence token has a related registration in the linked list of the root node. The current parsing position (usually a pointer / cursor / reference) is jumped from the parent node to the matched child node. Then, it is determined whether the sequence of the sequence token is the tail sequence of the sequence token set, that is, whether the current sequence token is the token of the last sequence of the sequence token set.

[0036] 105. When the sequence is not the tail sequence of the sequence token set, the child node corresponding to the matching result is written into the matching node set, and the sequence token of the next sequence in the sequence token set is read. In this embodiment, if the sequence of the previously read sequence token is not the last sequence of the sequence token set, the child node corresponding to the matching result, such as the show node, is written into the matching node set. Then, the sequence token of the next sequence in the sequence token set, such as the port, is read, until the sequence tokens of the entire sequence token set have been traversed and read.

[0037] 106. When it is the tail sequence of the sequence token set, then based on the matching node set, bind the execution function, and based on the execution function, generate the execution result.

[0038] In this embodiment, if the previously analyzed sequence token is the last sequence in the sequence token set, then based on the matching node set, the show node, port node, and status node are matched, the execution function matched by the above nodes is found in the node tree, the execution function is bound to the CLI command data, and the execution result is generated after data exchange through the execution function.

[0039] For details, please refer to Figure 3 , Figure 3 This is a schematic diagram of a specific embodiment of step 106 of the command execution method for an unmanaged switch in this invention. Step 106, "binding the execution function based on the matching node set," includes the following specific implementation methods: 1061. Determine whether the node type of the tail sequence node in the matching node set is ACTION type; 1062. When it is of type ACTION, the execution function of the tail sequence node mapping in the matching node set is bound; 1063. When it is not of type ACTION, an error message indicating that the command is incomplete is sent to the preset management serial port.

[0040] In steps 1061-1063, it is determined whether the last status node in the matching node set is of type ACTION. If it is of type ACTION, the execution function show_port_status() mapped to the status node is bound to the CLI command data for data exchange processing.

[0041] If it is not of type ACTION, it means that the CLI command data input is incomplete, the last executed function was not found in the node tree, and the last input sequence token is of type GROUP. An error message indicating that the command is incomplete is sent to the preset management serial port for the administrator to check the input CLI command data.

[0042] Specifically, the following detailed implementation method is included after step 106: 1064. The execution result is sent to the host computer via a preset management serial port or a USB to TTL cable.

[0043] In step 1064, the program running on the MCU, development board, or embedded device sends text information to the host computer on the PC via a serial port or USB-to-TTL cable, where it is displayed in the serial terminal. On the hardware link, the MCU / development board has two pins leading out: TX (transmit) and GND (ground) (some also have RX). If the computer does not have a native serial port, a USB-to-TTL converter cable (CH340, CP2102, FT232, etc.) is used. One end of the cable is a USB-A / USB-C connector that plugs into the computer, and the other end has three DuPont wires: TX, RX, and GND.

[0044] Furthermore, step 1064 also includes the following specific implementation methods: 10641. Insert the execution result into the ANSI control code to obtain the coloring execution result; 10642. The coloring execution result is sent to the host computer via a preset management serial port or a USB to TTL cable.

[0045] In steps 10641-10642, the original table string generated by show_port_status() is inserted into the ANSI color code to obtain the coloring execution result. The coloring execution result is then sent to the host computer via the on-chip UART serial port (or USB-TTL line) in bare-metal / bare-register mode.

[0046] For example: First insert ANSI color codes into the string: the original line Gi0 / 2 down 100M becomes Gi0 / 2[31mdown [0m [33m100M [0m].

[0047] The entire line Gi0 / 2 [31mdown [0m [33m100M [0m] is sent to the host computer via serial port 115200. The SecureCRT on the computer will show: Gi0 / 2 <red>down <restore> <yellow>100M <restore>. You can easily distinguish down / 100M without having to look up the manual.

[0048] In this embodiment of the invention, command-line operations are performed on resource-constrained unmanaged switches. A basic command tree is constructed, and the linked list is traversed from the root node. The user's CLI commands are broken down and matched one by one until a CLI command input by the user is matched. The bound execution function is then executed, and the execution result is output to the screen via a serial port. By leveraging the small space occupied by child node commands and the low retrieval complexity (O(n)) of a single-linked list, low memory consumption for CLI command execution is achieved, improving human-computer interaction efficiency and solving the technical problem of excessive memory consumption for CLI command execution in unmanaged switches.

[0049] Figure 4 This is a schematic diagram of the structure of a command execution device for an unmanaged switch according to an embodiment of the present invention. The command execution device 400 of the unmanaged switch can vary considerably due to different configurations or performance. It may include one or more central processing units (CPUs) 410 (e.g., one or more processors) and a memory 420, and one or more storage media 430 (e.g., one or more mass storage devices) for storing application programs 433 or data 432. The memory 420 and storage media 430 can be temporary or persistent storage. The program stored in the storage media 430 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the command execution device 400 of the unmanaged switch. Furthermore, the processor 410 may be configured to communicate with the storage media 430 and execute the series of instruction operations in the storage media 430 on the command execution device 400 of the unmanaged switch.

[0050] The command execution device 400 based on an unmanaged switch may also include one or more power supplies 440, one or more wired or wireless network interfaces 450, one or more input / output interfaces 460, and / or one or more operating systems 431, such as Windows Server, Mac OS X, Unix, Linux, Free BSD, etc. Those skilled in the art will understand that... Figure 4The command execution device structure of the unmanaged switch shown does not constitute a limitation on command execution devices based on unmanaged switches, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0051] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when the instructions are executed on a computer, cause the computer to perform the steps of the command execution method of the unmanaged switch.

[0052] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0053] Furthermore, although the operations are described in a specific order, this should be understood as requiring that such operations be performed in the specific order shown or in sequential order, or requiring that all illustrated operations be performed to achieve the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single implementation. Conversely, various features described in the context of a single implementation may also be implemented individually or in any suitable sub-combination in multiple implementations.

[0054] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

Claims

1. A command execution method for an unmanaged switch, characterized in that, Including the following steps: Receive CLI command data input by the user; According to the preset segmentation algorithm, the CLI command data is processed by sequence segmentation to obtain a sequence token set, and the sequence tokens in the sequence token set are read. The sequence tokens are matched according to the linked list of the preset root node to obtain the matching result; When the matching result is qualified, move to the child node corresponding to the matching result and determine whether the sequence of the sequence token is the tail sequence of the sequence token set; If the sequence is not the tail sequence of the sequence token set, the child node corresponding to the matching result is written into the matching node set, and the sequence token of the next sequence in the sequence token set is read. When it is the tail sequence of the sequence token set, the execution function is bound based on the matching node set, and the execution result is generated based on the execution function.

2. The command execution method for an unmanaged switch according to claim 1, characterized in that, Prior to the step of receiving CLI command data input by the user, the method further includes: Create a root node and set the node type of the child nodes in the root node, wherein the node type includes: GROUP type and ACTION type; When the node type is GROUP, the attributes of the child node are set, and the child node is attached to the root node; When the node type is ACTION, the execution function of the child node mapping is set, and the child node is mounted to the root node.

3. The command execution method for an unmanaged switch according to claim 2, characterized in that, The step of binding the execution function based on the matching node set includes: Determine whether the node type of the tail sequence node in the matching node set is ACTION type; When it is of type ACTION, the execution function of the tail sequence node mapping in the matching node set is bound; When it is not of type ACTION, an error message indicating an incomplete command is sent to the preset management serial port.

4. The command execution method for an unmanaged switch according to claim 3, characterized in that, All ACTION type child nodes corresponding to the root node are stored in a preset memory as const constants.

5. The command execution method for an unmanaged switch according to claim 1, characterized in that, After the step of generating the execution result based on the execution function, the method further includes: The execution results are sent to the host computer via a preset management serial port or a USB-to-TTL cable.

6. The command execution method for an unmanaged switch according to claim 5, characterized in that, The step of sending the execution result to the host computer via a preset management serial port or a USB-to-TTL cable includes: The execution result is inserted into the ANSI control code to obtain the colored execution result; The coloring execution results are sent to the host computer via a preset management serial port or a USB-to-TTL cable.

7. The command execution method for an unmanaged switch according to claim 1, characterized in that, After the step of matching the sequence tokens according to the linked list of the preset root node to obtain the matching result, the method further includes: If the matching result is unqualified, an error message for an unknown command is sent to the preset management serial port.

8. The command execution method for an unmanaged switch according to claim 1, characterized in that, After the step of receiving CLI command data input by the user, and before the step of performing sequence segmentation processing on the CLI command data according to a preset segmentation algorithm to obtain a sequence token set, the method further includes: Receive correction instructions from the user; According to the correction instruction, the CLI command data is adjusted to obtain corrected CLI command data, and the corrected CLI command data is assigned to the CLI command data.

9. A command execution device for an unmanaged switch, characterized in that, The command execution device of the unmanaged switch includes: a memory and at least one processor, wherein the memory stores instructions, and the memory and the at least one processor are interconnected via a line; The at least one processor invokes the instructions in the memory to cause the command execution device of the unmanaged switch to perform the command execution method of the unmanaged switch as described in any one of claims 1-8.

10. A computer-readable storage medium storing a computer program thereon, characterized in that, When the computer program is executed by the processor, it implements the command execution method for the unmanaged switch as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Method and device for realizing network equipment CLI (Command Line Interface for batch scripti) based on dynamic configuration

    CN101924656A

  • Data processing method and device, equipment and medium

    CN117424890A

  • Flow table parallel matching method and system of programmable switching chip

    CN120196961A

  • Method and device for data transmission

    WO2022011638A1