Command execution method, device and storage medium of unmanaged switch

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.

CN120935015BActive Publication Date: 2026-02-13SHENZHEN SCODENO TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511448632.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-11
Publication Date
2026-02-13
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.

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, reducing memory usage.

Benefits of technology

It enables CLI command execution with low memory consumption, improves human-computer interaction efficiency, and solves the problem of insufficient memory in unmanaged switches.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120935015B_ABST
    Figure CN120935015B_ABST
Patent Text Reader

Abstract

The application relates to the field of embedded interaction, and discloses a command execution method and device of a non-administrative 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; performing matching processing on the sequence token according to a chain table of a preset root node to obtain a matching result; when the matching result is qualified, moving to a sub-node corresponding to the matching result, judging whether the sequence of the sequence token is a tail sequence of the sequence token set; when the sequence is not the tail sequence, writing the sub-node corresponding to the matching result into a matching node set, and reading a next sequence token; and when the sequence is the 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 application, a sub-node command with low space occupation is matched through a CLI command, low memory consumption of CLI command execution is realized, and the human-computer interaction efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of embedded interaction, and in particular to a command execution method, device and storage medium of a non-administrative switch. BACKGROUND

[0002] The non-administrative switch is a plug-and-play Ethernet switching device, mainly completing the most basic data link layer forwarding work. The internal default parameters are fixed, and the MAC address is learned and the port-to-MAC mapping table is established automatically after power-on. The data frame is forwarded to the corresponding port according to the address table, and the terminal device interconnection is realized.

[0003] The traditional non-administrative switch relies on physical indicator lights (LEDs), and engineers need to infer the device running condition by combining multiple isolated indicator light states. There is a big contradiction between the resources and functions of the non-administrative switch, and the existing command line scheme (such as CLI library) needs to consume more than 10KB of RAM, which is far beyond the 4KB memory limit of the non-administrative switch. If forcibly transplanted, it will cause system crash. Therefore, for the technical problem of excessive memory consumption of CLI command execution of the non-administrative switch, a new technology is needed to solve the current problem. SUMMARY

[0004] The main purpose of the present application is to solve the technical problem of excessive memory consumption of CLI command execution of the non-administrative switch.

[0005] The first aspect of the present application provides a command execution method of a non-administrative switch, which comprises:

[0006] receiving CLI command data input by a user;

[0007] performing sequence segmentation processing on the CLI command data according to a preset segmentation algorithm to obtain a sequence token set, and reading a sequence token in the sequence token set;

[0008] performing matching processing on the sequence token according to a chain table of a preset root node to obtain a matching result;

[0009] 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;

[0010] when it is not the tail sequence of the sequence token set, writing the child node corresponding to the matching result into a matching node set, and reading a sequence token of a next sequence in the sequence token set;

[0011] when it is the tail sequence of the sequence token set, binding an execution function based on the matching node set, and generating an execution result based on the execution function.

[0012] Optionally, before the step of receiving the CLI command data, the method further comprises:

[0013] creating a root node, and setting a node type of a child node in the root node, wherein the node type comprises a GROUP type and an ACTION type;

[0014] when the node type is the GROUP type, setting an attribute of the child node, and mounting the child node to the root node;

[0015] when the node type is the ACTION type, setting an execution function mapped by the child node, and mounting the child node to the root node.

[0016] Optionally, in the second implementation manner of the first aspect, the step of binding the execution function based on the matched node set comprises:

[0017] judging whether a node type of a tail sequence node in the matched node set is the ACTION type;

[0018] when the node type is the ACTION type, binding an execution function mapped by the tail sequence node in the matched node set;

[0019] when the node type is not the ACTION type, sending error information that a command is incomplete to a preset management serial port.

[0020] Optionally, in the third implementation manner of the first aspect, all ACTION type child nodes corresponding to the root node are stored in a preset memory in a const constant form.

[0021] Optionally, in the fourth implementation manner of the first aspect, after the step of generating the execution result based on the execution function, the method further comprises:

[0022] sending the execution result to an upper computer through a preset management serial port or a USB-to-TTL line.

[0023] Optionally, in the fifth implementation manner of the first aspect, the step of sending the execution result to the upper computer through the preset management serial port or the USB-to-TTL line comprises:

[0024] inserting the execution result into an ANSI control code to obtain a dyeing execution result;

[0025] sending the dyeing execution result to the upper computer through the preset management serial port or the USB-to-TTL line.

[0026] Optionally, in the sixth implementation form of the first aspect of the present application, after the step of matching the sequence token according to the chain table of the preset root node to obtain a matching result, the method further comprises:

[0027] When the matching result is unqualified, error information of the unknown command is sent to the preset management serial port.

[0028] Optionally, in the seventh implementation form of the first aspect of the present application, after the step of receiving the CLI command data input by the user, and before the step of performing sequence segmentation processing on the CLI command data according to the preset segmentation algorithm to obtain a sequence token set, the method further comprises:

[0029] receiving a correction instruction of the user;

[0030] performing adjustment processing on the CLI command data according to the correction instruction to obtain corrected CLI command data, and assigning the corrected CLI command data as the CLI command data.

[0031] The second aspect of the present application provides a command execution device of a non-management switch, comprising a memory and at least one processor, the memory storing instructions, and the memory and the at least one processor being interconnected by a line; the at least one processor invoking the instructions in the memory to enable the command execution device of the non-management switch to perform the above-mentioned command execution method of the non-management switch.

[0032] The third aspect of the present application provides a computer readable storage medium, the computer readable storage medium storing instructions, when the instructions are run on a computer, enabling the computer to perform the above-mentioned command execution method of the non-management switch.

[0033] In the embodiment of the present application, by using command line operation on a resource-limited non-management switch, by constructing a basic command tree, traversing a chain table from a root node, splitting and matching CLI commands of the user one by one until a CLI command input by the user is hit, executing a bound execution function, and outputting an execution result to a screen through a serial port, low memory consumption of CLI command execution is realized, human-computer interaction efficiency is improved, and the technical problem of excessive memory consumption of CLI command execution of a non-management switch is solved. BRIEF DESCRIPTION OF DRAWINGS

[0034] Figure 1 FIG. 1 is a schematic diagram of an embodiment of the command execution method of the non-management switch in the embodiment of the present application;

[0035] Figure 2A specific embodiment diagram for step 101 of the command execution method of the non-managed switch in the embodiment of the present application;

[0036] Figure 3 A specific embodiment diagram for step 106 of the command execution method of the non-managed switch in the embodiment of the present application;

[0037] Figure 4 A specific embodiment diagram for the command execution device of the non-managed switch in the embodiment of the present application. DETAILED DESCRIPTION

[0038] The embodiment of the present application provides a command execution method, device and storage medium of a non-managed switch.

[0039] The embodiments of the present application will be described in detail below with reference to the accompanying drawings. Although some embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms, and should not be interpreted as being limited to the embodiments described herein, but rather, these embodiments are provided to more thoroughly and completely understand the present application. It should be understood that the drawings and embodiments of the present application are only for exemplary purposes, and are not intended to limit the scope of protection of the present application.

[0040] In the description of the embodiments of the present application, the term "comprising" and similar terms should be understood as open 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. can refer to different or the same objects. Other explicit and implicit definitions can also be included below.

[0041] For ease of understanding, the specific flow of the embodiment of the present application is described below. Please refer to Figure 1 An embodiment of the command execution method of the non-managed switch in the embodiment of the present application includes:

[0042] 101, receiving CLI command data input by a user;

[0043] In this embodiment, the CLI command data is a text instruction, and the command is entered one by one through the keyboard. Based on the Shell / interpreter, the input string is translated into a system call or a hardware operation.

[0044] The present application designs a layered command line system, which focuses on state monitoring and debugging information display, and does not involve configuration functions. The system is composed of three layers:

[0045] 1. Application layer (CLI interaction): responsible for input, parsing, and formatted output of CLI command execution results.

[0046] 2. Abstract layer (command management): build command tree, multi-level command matching, output command matching result.

[0047] 3. Driver layer (hardware adaptation): through fixed output stack buffer, no heap space allocation, output to PC terminal through serial port, and the PC terminal views the execution result.

[0048] For details, please refer to Figure 2 , Figure 2 is a specific embodiment diagram before step 101 of the command execution method of the non-management type switch in the embodiment of the application, and before step 101, the following specific embodiments are included:

[0049] 1011. Create a root node, and set the node type of the child node in the root node, wherein the node type includes: GROUP type, ACTION type;

[0050] 1012. When the node type is the GROUP type, set the attribute of the child node, and mount the child node to the root node;

[0051] 1013. When the node type is the ACTION type, set the execution function mapped by the child node, and mount the child node to the root node.

[0052] In steps 1011-1013, the root node is created, the node type of the child node under the root node is set, the basic command tree is statically built, and the show series command is supported. When the node type is the GROUP type, the GROUP type represents range / nested / priority structure information, does not generate any bytecode / machine code / IR instruction, has zero runtime overhead, and the number of child nodes is greater than or equal to 1. The attribute of the child node is set, and the child node is mounted to the node tree of the root node. The child node of the GROUP type will have subsequent child nodes.

[0053] When the node type is the ACTION type, the ACTION type represents operation / control / side effect behavior information, the execution function mapped by the child node is set, and the child node is mounted to the last node leaf of the node tree of the root node. The child node of the ACTION type will not have subsequent child nodes.

[0054] Register all child nodes of the GROUP type and the ACTION type to the parent command group, and establish the node tree based on the root node based on the parent-child association relationship.

[0055] Specifically, all ACTION type child nodes corresponding to the root node are stored in a preset memory in a const constant form. In a compilation phase, a command array is generated, a command tree structure is solidified at a compilation stage through a pre-compiled macro, ACTION type child nodes are stored in a preset memory in a const constant form, and ACTION type child nodes occupy a small space, and 50 only occupy 1.2 KB of a storage area.

[0056] 102. performing sequence segmentation processing on the CLI command data according to a preset segmentation algorithm to obtain a sequence token set, and reading a sequence token in the sequence token set;

[0057] In the embodiment, the segmentation algorithm can perform sequence segmentation processing on the CLI command data according to spaces, setting characters and the like, and establish a sequence token set according to an original CLI command data order. For example, the input CLI command data is “show port status”, the segmented sequence token set is [’show’, ’port’, ’status’], and then the sequence token in the sequence token set is read.

[0058] Further, after the step 101 and before the step 102, the embodiment further includes the following specific implementation:

[0059] 1021. receiving a correction instruction of a user;

[0060] 1022. performing adjustment processing on the CLI command data according to the correction instruction to obtain corrected CLI command data, and assigning the corrected CLI command data to the CLI command data.

[0061] In the steps 1021-1022, a backspace key of the user is received to correct input in real time, the CLI command data is adjusted based on the correction instruction to generate corrected CLI command data. Then, the corrected CLI command data is re-assigned to the CLI command data for subsequent processing. For example, A is the CLI command data, the value of A is originally m, which is adjusted to n by the correction instruction, and then n is assigned to A, and finally the result is that A is n.

[0062] 103. performing matching processing on the sequence token according to a preset root node chain table to obtain a matching result;

[0063] In the embodiment, the sequence tokens are read in sequence during reading, for example, the sequence tokens of show, port and status are read in sequence in [’show’, ’port’, ’status’]. Based on the root node chain table, the read sequence tokens are matched to generate a matching result.

[0064] Specifically, the following specific embodiments are further included after step 103:

[0065] 1031. When the matching result is unqualified, an error message of unknown command is sent to the preset management serial port.

[0066] In step 1031, if the matching structure is unqualified, the sequence token does not have a related registration in the chain table of the root node, and an error message of unknown command is sent to the preset management serial port, so that the management personnel analyzes whether the CLI instruction data is inputted incorrectly.

[0067] 104. When the matching result is qualified, the sub-node corresponding to the matching result is moved to, and it is judged whether the sequence of the sequence token is the tail sequence of the sequence token set.

[0068] In the embodiment, when the matching result is qualified, it is indicated that the sequence token has a related registration in the chain table of the root node, the current analysis position (usually a pointer / cursor / reference) is jumped from the parent node to the matched sub-node, and then it is judged whether the sequence of the sequence token is the tail sequence of the sequence token set, that is, whether the sequence token is the last sequence token of the sequence token set.

[0069] 105. When the sequence token is not the tail sequence of the sequence token set, the sub-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.

[0070] In the embodiment, if the sequence of the last read sequence token is not the tail sequence of the sequence token set, the sub-node corresponding to the matching result, such as the show node, is written into the matching node set, and then the sequence token of the next sequence in the sequence token set, such as the port, is read until the sequence token of the entire sequence token set is read.

[0071] 106. When the sequence token 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.

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

[0073] Specifically, please refer to Figure 3 , Figure 3For a specific embodiment of step 106 of the command execution method of the non-managed switch in the embodiments of the present application, "binding an execution function based on the matched node set" in step 106 includes the following specific implementation:

[0074] 1061, judging whether the node type of the tail sequence node in the matched node set is ACTION type;

[0075] 1062, when it is ACTION type, binding the execution function mapped by the tail sequence node in the matched node set;

[0076] 1063, when it is not ACTION type, sending error information of incomplete command to the preset management serial port.

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

[0078] If it is not ACTION type, it means that the CLI command data input is incomplete, the last execution execution function is not found on the node tree, the last input sequence token is GROUP type, and error information of incomplete command is sent to the preset management serial port for checking the input CLI command data by the management personnel.

[0079] Specifically, after step 106, the following specific implementation is further included:

[0080] 1064, sending the execution result to the host computer through the preset management serial port or USB to TTL line.

[0081] In step 1064, the program running in MCU, development board or embedded device sends text information to the host computer of PC end through "serial port" or "USB to TTL line" and displays it in the serial terminal. On the hardware link, MCU / development board leads out two pins of TX (transmit) and GND (ground) (some lead out RX). When the computer does not have a native serial port, a USB to TTL conversion line (CH340, CP2102, FT232, etc.) is inserted. One end of the line is USB-A / USB-C inserted into the computer, and the other end is 3 Dupont lines: TX, RX, GND.

[0082] Further, in step 1064, the following specific implementation is further included:

[0083] 10641, inserting the execution result into ANSI control code to obtain dyeing execution result;

[0084] 10642、Through preset management serial port or USB-TTL line, the dyeing execution result is sent to the host computer.

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

[0086] For example, the original line Gi0 / 2 down 100M is first inserted into the string to obtain ANSI color code: Gi0 / 2 [31mdown [0m [33m100M [0m.

[0087] The whole line Gi0 / 2 [31mdown [0m [33m100M [0m is sent to the host computer through the serial port 115200, and the SecureCRT on the computer sees: Gi0 / 2<red>down<restore><yellow>100M<restore>, which can be distinguished at a glance, and the manual does not need to be referred to again.

[0088] In the embodiment of the application, by using command line operation on a resource-restricted non-managed switch, a basic command tree is constructed, a list is traversed from a root node, a CLI command of a user is split and matched one by one until the CLI command input by the user is hit, a bound execution function is executed, and an execution result is output to a screen through a serial port. By the characteristics of small space occupation of a command of a sub-node and low search complexity O(n) of a single-item list, low memory consumption of CLI command execution is realized, human-computer interaction efficiency is improved, and the technical problem of too large memory consumption of CLI command execution of a non-managed switch is solved.

[0089] Figure 4is a structural schematic diagram of a non-managed switch command execution device provided by an embodiment of the present application. The non-managed switch command execution device 400 can have a large difference due to different configurations or performances, and can include one or more central processing units (CPUs) 410 (for example, one or more processors) and a memory 420, one or more storage media 430 (for example, one or more mass storage devices) storing an application program 433 or data 432. The memory 420 and the storage media 430 can be temporary storage or persistent storage. The program stored in the storage media 430 can include one or more modules (not shown in the figure), and each module can include a series of instruction operations on the non-managed switch command execution device 400. Further, the processor 410 can be configured to communicate with the storage media 430 and execute the series of instruction operations in the storage media 430 on the non-managed switch command execution device 400.

[0090] The non-managed switch command execution device 400 can 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, and the like. Those skilled in the art can understand that the non-managed switch command execution device 400 can include other components, and the components can be combined or arranged differently. Figure 4 The illustrated non-managed switch command execution device structure does not constitute a limitation on the non-managed switch command execution device, and can include more or fewer components than those shown, or combine certain components, or arrange different components.

[0091] The present application also provides a computer readable storage medium, which can be a non-volatile computer readable storage medium or a volatile computer readable storage medium. The computer readable storage medium stores instructions, and when the instructions are run on a computer, the computer executes the steps of the non-managed switch command execution method.

[0092] In the context of this disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the foregoing.

[0093] Moreover, while operations have been depicted in a particular order, this should not be understood as requiring such order nor that all illustrated operations be performed, to achieve desirable results. In certain circumstances, multitasking and parallel processing can be advantageous. Likewise, while several specific implementation details have been discussed, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable sub-combination.

[0094] Although the subject matter has been described in language specific to structural features and / or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms 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, the parsing position is moved from the parent node to the child node corresponding to the matching result, and it is determined 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, then based on the matching node set, an execution function is bound, and based on the execution function, an execution result is generated; 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; 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; The step of matching the sequence tokens according to the linked list of the preset root node to obtain the matching result further includes: If the matching result is unqualified, an error message for an unknown command is sent to the preset management serial port.

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

3. 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.

4. The command execution method for an unmanaged switch according to claim 3, 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.

5. 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.

6. 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-5.

7. 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-5.

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