A method, device, switch and storage medium for dynamically generating configuration files

By monitoring SNMP database tables and netlink messages, and sending configuration file update requests to the update process, the problem of configuration file update when the SNMP switch device is restarted is solved, and the timely update and accuracy of the configuration file are achieved.

CN115941422BActive Publication Date: 2024-10-22INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202211282644.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-19
Publication Date
2024-10-22
Estimated Expiration
2042-10-19

AI Technical Summary

Technical Problem

When the existing SNMP switch restarts the device, the configuration file is incorrectly generated and cannot be updated in time. In particular, the process startup sequence of the IP address and VRF causes the configuration file update to fail.

Method used

Use a listening process to subscribe to the SNMP database table, monitor key value changes, receive netlink messages, and send configuration file update requests to the update process to ensure that the configuration file is updated in a timely manner.

Benefits of technology

Ensure that the SNMP configuration file is consistent with the actual configuration, avoid configuration file generation errors, and achieve timely update of the configuration file.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115941422B_ABST
    Figure CN115941422B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a method, device, switch and storage medium for dynamically generating a configuration file. The method is applied to a switch, the switch is configured with SNMP, and runs a monitoring process and an update process. The method includes: the monitoring process subscribes to the database table of SNMP and monitors the changes of key values ​​in the database table; the monitoring process receives the netlink message sent by the switch kernel, and the netlink message includes the change message of the IP address and the change message of the VRF; if the key value in the database table changes and / or the change message of the IP address and / or the change message of the VRF is received, the monitoring process sends an update request of the SNMP configuration file to the update process; the update process determines whether to update the configuration file according to the update request. It ensures that the configuration file of SNMP is consistent with the actual configuration, so that the configuration file of SNMP can be updated in time, and the generation error of the configuration file of SNMP is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of simple network management protocol, and in particular to a method for dynamically generating a configuration file, a device for dynamically generating a configuration file, a switch and a computer-readable storage medium. Background Art

[0002] Simple Network Management Protocol (SNMP) is a simple network management protocol. It belongs to the application layer protocol in the TCP / IP five-layer protocol and is a protocol used for network management.

[0003] When the user modifies the monitoring configuration of the SNMP switch or the configuration relationship of the virtual routing and forwarding (VRF), port, and IP address changes, the configuration file of the SNMP switch needs to be updated. Currently, netlink is used to monitor the configuration relationship changes of VRF, port, and IP address, but there are limitations. For example, when the device is restarted, various services are being prepared. When the process of the configuration file starts to run the detection configuration, the process of maintaining the IP address and port has not yet started, resulting in an error in the generation of the configuration file; when the process of maintaining the IP address and VRF is started, the correct relationship of the port is written to the database, but the netlink message of the IP address or VRF cannot be received, and the configuration file cannot be updated in time. Summary of the invention

[0004] In view of the above problems, embodiments of the present invention are proposed to provide a method for dynamically generating a configuration file, a corresponding device for dynamically generating a configuration file, a switch, and a computer-readable storage medium that overcome the above problems or at least partially solve the above problems.

[0005] In order to solve the above problem, an embodiment of the present invention discloses a method for dynamically generating a configuration file, which is applied to a switch, wherein the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an update process, and the method includes:

[0006] The monitoring process subscribes to the SNMP database table and monitors changes in key values ​​in the database table; the key values ​​include VRF key-value pairs and IP address key-value pairs;

[0007] The monitoring process receives the netlink message sent by the switch kernel, wherein the netlink message includes a change message of the IP address and a change message of the virtual routing forwarding VRF;

[0008] If the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process;

[0009] After receiving the update request, the update process determines whether the configuration file needs to be updated, and updates the configuration file if the configuration file needs to be updated.

[0010] Optionally, the database includes multiple IP addresses, and if the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process, including:

[0011] In the case where the netlink message is a change of the IP address, determining whether the IP address exists in the database;

[0012] If the IP address exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0013] Optionally, the IP address includes a valid IP address, and after receiving the update request, the update process determines whether the configuration file needs to be updated, and if the configuration file needs to be updated, updates the configuration file, including:

[0014] If the IP address is a valid IP address, and the change of the IP address is deletion or addition of the IP address, the update process generates a configuration file for deleting or adding the IP address, and updates the SNMP configuration file based on the configuration file for deleting or adding the IP address.

[0015] Optionally, the database further includes a plurality of VRFs, and if the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process, including:

[0016] If the netlink message is a change of the VRF, determining whether the port name of the VRF interface exists in the database;

[0017] If the VRF exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0018] Optionally, the VRF includes a valid VRF, and after receiving the update request, the update process determines whether the configuration file needs to be updated, and if the configuration file needs to be updated, updates the configuration file, including:

[0019] If the VRF is a valid VRF, and the change of the VRF is deletion or addition of the VRF, the update process generates a configuration file for deleting or adding the VRF, and updates the SNMP configuration file according to the configuration file for deleting or adding the VRF.

[0020] Optionally, it also includes:

[0021] During the operation of the switch, when the update process receives multiple update requests from the monitoring process and updates the configuration file, one of the multiple update processes acquires a file lock to exclusively occupy the configuration file and performs a write operation or a read operation.

[0022] Optionally, it is characterized in that the file lock stores an identifier of an updating process being used, and the method further comprises:

[0023] When one of the plurality of update processes requests file lock permission, determining whether the file lock has the identifier;

[0024] If there is an identifier, query whether the update process that exclusively holds the file lock is alive;

[0025] If it survives, wait for the update process that exclusively holds the file lock to release the file lock.

[0026] The embodiment of the present invention discloses a device for dynamically generating a configuration file, which is applied to a switch, wherein the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an update process, and the device comprises:

[0027] A subscription module, used for the monitoring process to subscribe to the SNMP database table and monitor changes in key values ​​in the database table; the key values ​​include VRF key-value pairs and IP address key-value pairs;

[0028] A receiving module, used for the monitoring process to receive a netlink message sent by the switch kernel, wherein the netlink message includes an IP address change message and a virtual routing forwarding VRF change message;

[0029] A sending module, configured to cause the monitoring process to send an update request for the SNMP configuration file to the update process if the key value in the database table changes and / or a change message of the IP address and / or a change message of the VRF is received;

[0030] The updating module is used for determining whether the configuration file needs to be updated after the updating process receives the updating request, and updating the configuration file if the configuration file needs to be updated.

[0031] Optionally, the database includes multiple IP addresses, and the sending module includes:

[0032] A first judgment submodule, configured to judge whether the IP address exists in the database when the netlink message is a change of the IP address;

[0033] The first sending submodule is used for, if the IP address exists in the database, the monitoring process sending an update request for the SNMP configuration file to the update process.

[0034] Optionally, the IP address includes a valid IP address, and the update module includes:

[0035] The first update submodule is used for, if the IP address is a valid IP address and the change of the IP address is deletion or addition of the IP address, the update process generates a configuration file for deleting or adding the IP address, and updates the SNMP configuration file according to the configuration file for deleting or adding the IP address.

[0036] Optionally, the database further includes a plurality of VRFs, and the sending module includes:

[0037] A second judgment submodule is used to judge whether the port name of the VRF interface exists in the database if the netlink message is a change of the VRF;

[0038] The second sending submodule is used for, if the VRF exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0039] Optionally, the VRF includes a valid VRF, and the update module includes:

[0040] The second update submodule is used for, if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, the update process generates a configuration file for deleting or adding the VRF, and updates the SNMP configuration file according to the configuration file for deleting or adding the VRF.

[0041] Optionally, it also includes:

[0042] The exclusive lock acquisition module is used to acquire a file lock to exclusively own the configuration file and perform a write operation or a read operation when the update process receives multiple update requests from the monitoring process and updates the configuration file during the operation of the switch.

[0043] Optionally, the file lock stores an identifier of an updating process being used, and the device further comprises:

[0044] The judgment module is used to judge whether the file lock has the identifier when one of the multiple update processes requests the file lock permission; if it has the identifier, query whether the update process that exclusively occupies the file lock is alive; if it is alive, wait for the update process that exclusively occupies the file lock to release the file lock.

[0045] An embodiment of the present invention further discloses an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the steps of the method for dynamically generating a configuration file as described above when executed by the processor.

[0046] The embodiment of the present invention further discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for dynamically generating a configuration file as described above are implemented.

[0047] The embodiments of the present invention include the following advantages:

[0048] In the embodiment of the present invention, the monitoring process subscribes to the database table of SNMP and monitors the changes of key values ​​in the database table; the key values ​​include VRF key value pairs and IP address key value pairs; the monitoring process receives the netlink message sent by the switch kernel, and the netlink message includes the change message of the IP address and the change message of the virtual routing forwarding VRF; if the key value in the database table changes, and / or, the change message of the IP address and / or the change message of the VRF is received, the monitoring process sends an update request of the SNMP configuration file to the update process; after receiving the update request, the update process determines whether the configuration file needs to be updated, and updates the configuration file if the configuration file needs to be updated. This ensures that the configuration file of SNMP is consistent with the actual configuration, so that the configuration file of SNMP can be updated in time, and avoids the generation error of the configuration file of SNMP. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 is a flowchart of a method for dynamically generating a configuration file provided by an embodiment of the present invention;

[0050] Figure 2The present invention provides a structural block diagram of a device for dynamically generating a configuration file. DETAILED DESCRIPTION

[0051] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0052] Simple Network Management Protocol (SNMP) is a network protocol used to manage and monitor network-attached devices in an Internet Protocol network.

[0053] SNMP technology is a method that uses the SNMP protocol to automatically help administrators collect network operation status in large-scale network management, helping network administrators to understand the operation status of network devices that are not around in real time. In this way, network administrators only need to sit at their own positions to understand the operation status of the entire company's network devices. With this simple network management protocol, network administrators can easily exchange management information between SNMP agents (Agents) and SNMP management stations (Network Management Stations, NMS).

[0054] 1. SNMP has the following advantages:

[0055] 1) Automated network management. Network administrators can use the SNMP platform to retrieve information, modify information, discover faults, complete fault diagnosis, perform capacity planning, and generate reports on nodes on the network.

[0056] 2) Shield the physical differences between different devices and realize the automated management of products from different manufacturers. SNMP only provides the most basic set of functions, making the management tasks relatively independent of the physical characteristics of the managed devices and the underlying networking technology, thereby realizing the management of devices from different manufacturers, which is particularly suitable for use in small, fast and low-cost environments.

[0057] 2. Working mechanism of SNMP

[0058] SNMP network elements are divided into two types: NMS and Agent.

[0059] 1) NMS (Network Management Station) is a workstation running SNMP client program, which can provide a very friendly human-computer interaction interface to facilitate network administrators to complete most network management tasks.

[0060] 2) Agent is a process resident on the device, responsible for receiving and processing request messages from NMS. In some emergency situations, such as changes in interface status, Agent will also actively notify NMS.

[0061] 3) NMS is the manager of SNMP network, and Agent is the managed of SNMP network. NMS and Agent exchange management information through SNMP protocol.

[0062] 4)SNMP provides four basic operations:

[0063] Get operation: The NMS uses this operation to query the value of one or more objects of the Agent.

[0064] Set operation: The NMS uses this operation to reset the value of one or more objects in the Agent database (MIB, Management Information Base).

[0065] Trap operation: The Agent uses this operation to send alarm information to the NMS.

[0066] Inform operation: The NMS uses this operation to send alarm information to other NMSs.

[0067] Netlink is an IPC (Inter Process Commumicate) mechanism, which is a mechanism for communication between the kernel and user space. It is also used for inter-process communication (Netlink is more used for kernel communication, and communication between processes mostly uses Unix domain sockets).

[0068] Virtual Routing and Forwarding (VRF) can divide the routes on the same device into different groups, and then forward the routes according to the requested interface and destination address.

[0069] In the embodiment of the present invention, a snmpd process may be run in the SNMP switch. The snmpd process may be an update process and may use the SNMP protocol to disclose various information.

[0070] Snmpd-conf is the configuration file of SNMP, which defines the network address and port number that the SNMP process monitors.

[0071] The SNMP process is the part of the actual network device that implements the SNMP function. Usually, the SNMP process receives the read and write request messages from the NMS on UDP port 161, and the management station receives the event notification messages from the agent on UDP port 162. Therefore, once the access rights to the device are obtained, the device information can be accessed, and the device parameters can be modified and configured.

[0072] When the user modifies the IP address or modifies the configuration relationship between the port and VRF, the existing method of monitoring the changes in the IP address and VRF cannot update the configuration file in time when the device is restarted, resulting in configuration file generation errors. After the modified configuration relationship is written to the database, the Netlink message of the IP address or the modification of the configuration relationship between the port and VRF cannot be received, resulting in the configuration file not being updated in time.

[0073] One of the core concepts of the embodiment of the present invention is to monitor the changes of database table key values ​​by running a monitoring process, subscribing to the database table, and monitoring the changes of IP addresses and VRFs through Netlink. When the changes of database table key values ​​and / or IP addresses and / or VRFs are monitored, a request to update the configuration file can be sent to the update process in time. The update process determines whether an update is required based on the update request, and updates the configuration file if an update is required. This ensures that the SNMP configuration file is consistent with the actual configuration, so that the configuration file can be updated in time, and avoids configuration file generation errors.

[0074] Reference Figure 1 , shows a flowchart of the steps of a method for dynamically generating a configuration file provided by an embodiment of the present invention, which is applied to a switch, wherein the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an update process. The method may specifically include the following steps:

[0075] Step 101, the monitoring process subscribes to the SNMP database table and monitors the changes of key values ​​in the database table; the key values ​​include VRF key-value pairs and IP address key-value pairs.

[0076] In the embodiment of the present invention, the SNMP database table can be subscribed to when monitoring is started, and the changes of key values ​​in the database table can be monitored by subscribing to the SNMP database table. The key values ​​may include VRF key-value pairs and IP address key-value pairs.

[0077] As an example, the database of SNMP can be a key-value store. The key-value store is mainly used when all database accesses are operated through primary keys. For the key-value store, the basic data model is the key-value model. The key is of String type, and the value is a basic data type, such as String, integer, etc. The key-value store can perform operations such as writing or updating a key-value pair, reading the corresponding value according to a key, and deleting the entire key-value pair according to a key.

[0078] For example, the client can query the value according to the key, set the value corresponding to the key, or delete the key from the database. The application can provide the key and value and persist the key-value pair. If the key already exists, the current value is overwritten with the new value, otherwise a new data is created.

[0079] As an example, the SubscriberStateTable function can be used to indicate which key in which database, for example, the MGMT_VRF_CONFIG key in the configuration database (config-db), which indicates whether the management port of the device is added to the network management port (mgmt), so that changes in the key value in the key can be monitored.

[0080] For example, in the SNMP database table, there is a key called VRF, whose key value is VRF1. When a user creates a new VRF2, the monitoring process monitors the change in the database key value.

[0081] Step 102: The monitoring process receives a netlink message sent by the switch kernel, wherein the netlink message includes an IP address change message and a virtual routing forwarding VRF change message.

[0082] Exemplarily, the monitoring process may receive a netlink message sent by the switch kernel, where the netlink message may be an IP address change message or a VRF change message.

[0083] As an example, a user can assign different ports to different VRF interfaces. A VRF interface can have multiple hardware ports, and a hardware port can only belong to one VRF interface.

[0084] As an example, when the user changes the IP address, the kernel can send a netlink message of the IP address change to the listening process.

[0085] As an example, when a user modifies a port, the relationship between the VRF and the port changes, and the kernel can send a netlink message of the VRF change to the listening process.

[0086] Step 103: If the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0087] Exemplarily, when the key value in the database table changes, the monitoring process is triggered to send a request to update the configuration file to the configuration file update process; when the IP address change message and / or the VRF change message is received, the monitoring process is triggered to send a request to update the configuration file to the configuration file update process.

[0088] As an example, the change of the key value may include adding or deleting a VRF key-value pair in the database table.

[0089] In an embodiment of the present invention, the database includes multiple IP addresses, and if the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the configuration file of the SNMP switch to the update process, including: when the netlink message is a change of the IP address, determining whether the IP address exists in the database; if the IP address exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0090] In the embodiment of the present invention, the SNMP database may include multiple IP addresses, and all the IP addresses in the database are related to SNMP.

[0091] Exemplarily, the change of IP address may include the addition of IP address and the deletion of IP address. When receiving the netlink message of IP address change, first determine whether there is a corresponding IP address in the database. If there is a corresponding IP address, it means that the changed IP address is the IP address of SNMP, and the monitoring process can be triggered to send a request to update the SNMP configuration file to the update process; if there is no corresponding IP address, it means that the changed IP address is not the IP address of SNMP, and the monitoring process will not be triggered to send a request to update the SNMP configuration file to the update process.

[0092] In an embodiment of the present invention, the database also includes multiple VRFs. If the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process, including: if the netlink message is a change of the VRF, determining whether the port name of the VRF interface exists in the database; if the VRF exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0093] In the embodiment of the present invention, the SNMP database may include multiple VRFs, and the VRFs in the database are all related to SNMP. Each VRF in the database includes multiple ports, and each port corresponds to an IP address.

[0094] Exemplarily, the change of VRF may refer to the change of the relationship between VRF and port, for example, adding VRF or deleting VRF will change the corresponding relationship between VRF and port. When receiving the netlink message of VRF change, first determine whether there is a corresponding VRF in the database. If there is a corresponding VRF, it means that the changed VRF is the VRF of SNMP, and the monitoring process can be triggered to send a request to update the SNMP configuration file to the update process; if there is no corresponding VRF, it means that the changed VRF is not the VRF of SNMP, and the monitoring process will not be triggered to send a request to update the SNMP configuration file to the update process.

[0095] In the embodiment of the present invention, two processes are respectively responsible for implementing different functions and completing the update of the configuration file. Each process is responsible for a single functional task, and the functional coupling between processes is not strong. Compared with one process completing all tasks, the use of two processes focusing on different functions is convenient for reuse and reduces the lengthy and tedious process of function implementation.

[0096] Step 104: After receiving the update request, the update process determines whether the configuration file needs to be updated, and updates the configuration file if the configuration file needs to be updated.

[0097] Exemplarily, when the update process receives an update request, it may check and determine whether the configuration file needs to be updated. If the configuration file needs to be updated, the SNMP configuration file is updated.

[0098] For example, a user can create a new VRF in the command line and assign the corresponding port to the VRF. The database can add a new VRF and port number according to the command. The monitoring process can determine whether the newly added VRF is an SNMP-related VRF. If so, it can send an update request to the update process. After receiving the update request, the update process can generate a configuration file containing the newly added VRF and can update the original configuration file according to the newly generated configuration file.

[0099] In one embodiment of the present invention, the IP address includes a valid IP address. After receiving the update request, the update process determines whether the configuration file needs to be updated. If the configuration file needs to be updated, the configuration file is updated, including: if the IP address is a valid IP address, and the change of the IP address is to delete or add the IP address, the update process generates a configuration file for deleting or adding the IP address, and updates the SNMP configuration file based on the configuration file for deleting or adding the IP address.

[0100] In the embodiment of the present invention, the SNMP database may include multiple IP addresses, and the multiple IP addresses may be divided into valid IP addresses and invalid IP addresses.

[0101] As an example, when the update process determines that the deleted or added IP address is a valid IP address, a configuration file for deleting or adding the IP address may be generated, and the SNMP configuration file may be updated according to the configuration file for deleting or adding the IP address.

[0102] As an example, the SNMP configuration file may include parameters such as IP address, VRF, relationship between VRF and port, etc. Among them, VRF, port, and IP address may be a column of associated data, and when VRF or IP address is added or deleted, VRF, port, and IP address may be added or deleted at the same time.

[0103] For example, the user can add an IP address in the command window of the switch. The kernel of the switch can send the message of the IP address addition to the monitoring process through netlink. After receiving the netlink message of the IP address addition, the monitoring process determines whether the added IP address exists in the SNMP database. If the added IP address exists in the SNMP database, a request to update the configuration file is sent to the update process. After receiving the request to update the configuration file, the update process determines whether the added IP address is a valid IP address in the SNMP database. If it is not a valid IP address, the IP address is not updated. If it is a valid IP address, a configuration file containing the newly added IP address is generated, and the original configuration file is updated according to the configuration file containing the newly added IP address.

[0104] For example, a user can delete an IP address in the command window of the switch. The kernel of the switch can send a message of IP address deletion to the listening process through netlink. After receiving the netlink message of IP address deletion, the listening process determines whether the deleted IP address exists in the SNMP database. If the deleted IP address exists in the SNMP database, a request to update the configuration file is sent to the updating process. After receiving the request to update the configuration file, the updating process determines whether the deleted IP address is a valid IP address in the SNMP database. If it is not a valid IP address, the IP address is not updated. If it is a valid IP address, a configuration file containing the deleted IP address is generated, and the original configuration file is updated according to the configuration file containing the deleted IP address.

[0105] In an embodiment of the present invention, when the changed IP address is a valid IP address in the database, the update process can update the configuration file. When the changed IP address is an invalid IP address, the configuration file is not updated, thereby reducing unnecessary operations, avoiding blind updates, and increasing the storage space of the device.

[0106] In an embodiment of the present invention, the VRF of the SNMP switch includes a valid VRF. After receiving the update request, the update process determines whether the configuration file needs to be updated. If the configuration file needs to be updated, the configuration file is updated, including: if the VRF is a valid VRF, and the change of the VRF is to delete or add the VRF, then the update process generates a configuration file for deleting or adding the VRF, and updates the configuration file of the SNMP switch according to the configuration file for deleting or adding the VRF.

[0107] Exemplarily, in the embodiment of the present invention, the SNMP database may include multiple VRFs, and the multiple VRFs may be divided into valid VRFs and invalid VRFs.

[0108] As an example, when the update process determines that the deleted or added VRF is a valid VRF, a configuration file for the deleted or added VRF may be generated, and the SNMP configuration file may be updated according to the configuration file for the deleted or added VRF.

[0109] As an example, when a user can delete or add a VRF through a command line in a switch, the database changes the value of the VRF in the database according to the command to delete or add the VRF issued by the command line.

[0110] As an example, the SNMP configuration file may include parameters such as IP address, VRF, relationship between VRF and port, etc. Among them, VRF, port, and IP address may be a column of associated data, and when VRF or IP address is added or deleted, VRF, port, and IP address may be added or deleted at the same time.

[0111] For example, a user can delete a VRF in the command window of the switch. The kernel of the switch can send a VRF deletion message to the listening process through netlink. The listening process receives the VRF deletion message through netlink and determines whether the deleted VRF exists in the SNMP database. If the deleted VRF exists in the database, the updating process is requested to update the configuration file. After receiving the request to update the configuration file, the updating process determines whether the deleted VRF is a valid VRF in the database. If it is not a valid VRF, the VRF is not updated. If it is a valid VRF, a configuration file containing the deleted VRF is generated, and the original configuration file is updated according to the configuration file containing the deleted VRF.

[0112] For example, a user can create a new VRF in the command window of the switch and assign the port to the newly created VRF. The kernel of the switch can send the VRF addition message to the listening process through netlink. The listening process receives the VRF addition message through netlink and determines whether the added VRF exists in the SNMP database. If the added VRF exists in the database, the updating process is requested to update the configuration file. After receiving the request to update the configuration file, the updating process determines whether the added VRF is a valid VRF in the database. If it is not a valid VRF, the VRF is not updated. If it is a valid VRF, a configuration file containing the added VRF is generated, and the original configuration file is updated according to the configuration file containing the added VRF.

[0113] In an embodiment of the present invention, when the changed VRF is a valid VRF in the database, the update process can update the configuration file. When the changed VRF is an invalid VRF, the configuration file may not be updated, thereby reducing unnecessary operations, avoiding blind updates, and increasing the storage space of the device.

[0114] In one embodiment of the present invention, during the operation of the switch, when the update process receives multiple update requests from the listening process and updates the configuration file, one of the multiple update processes acquires a file lock to exclusively occupy the configuration file and performs a write operation or a read operation.

[0115] As an example, when the listening process sends multiple update requests to the update process at the same time, contention problems may occur when the corresponding multiple update processes perform read or write operations on the configuration files. For example, read operations and write operations are performed at the same time, or when multiple update processes perform write operations at the same time, configuration file update errors may occur due to contention for the configuration files.

[0116] As an example, to prevent multiple update processes from reading and / or writing the same configuration file at the same time, a file lock permission may be requested when preparing to read or write the file.

[0117] For example, the update process includes update process 1, update process 2, and update process 3. Update process 1 writes the configuration file, update process 2 reads the configuration file, and update process 3 writes the configuration file. The three processes operate simultaneously, so that update process 1 first obtains the file lock, monopolizes the configuration file and performs the write operation, and update process 2 and update process 3 wait in line and release the file lock after update process 1 completes the write operation; update process 2 then obtains the file lock, monopolizes the configuration file for reading operation, and releases the file lock after update process 2 completes the write operation; update process 3 then obtains the file lock, monopolizes the configuration file for reading operation, until update process 3 completes the write operation and releases the file lock, thereby completing the update of the configuration file and avoiding configuration file update errors caused by contention for configuration files.

[0118] In an embodiment of the present invention, when the monitoring process generates multiple update requests, repeated update requests are filtered, and the filtered update requests are sent to the update process.

[0119] Exemplarily, when the monitoring process generates multiple update requests, the repeated update requests may be filtered out first, and then the filtered update requests may be sent to the update process, thereby improving the running speed of the device.

[0120] In one embodiment of the present invention, the file lock stores an identifier of an update process that is currently in use, and the method further includes: when one of the multiple update processes requests file lock permission, determining whether the file lock has the identifier; if it has the identifier, querying whether the update process that exclusively occupies the file lock is alive; if it is alive, waiting for the update process that exclusively occupies the file lock to release the file lock.

[0121] As an example, a file lock can store the identifier of the update process that is currently using it. When an update process among multiple update processes requests file lock permission, it can be determined whether the file lock has the process identifier; if it has the identifier, it will query whether the update process that exclusively holds the file lock is alive; if it is alive, it will wait for the update process that exclusively holds the file lock to release the file lock, thereby effectively identifying whether there is a process that currently exclusively holds the file lock.

[0122] In an embodiment of the present invention, the monitoring process subscribes to the database table of the SNMP and monitors the changes of the key values ​​in the database table; the key values ​​include VRF key value pairs and IP address key value pairs; the monitoring process receives the netlink message sent by the switch kernel, and the netlink message includes the change message of the IP address and the change message of the virtual routing forwarding VRF; if the key value in the database table changes, and / or, the change message of the IP address and / or the change message of the VRF is received, the monitoring process sends the update request of the SNMP configuration file to the update process; after receiving the update request, the update process determines whether the configuration file needs to be updated, and updates the configuration file if the configuration file needs to be updated. This ensures that the SNMP configuration file is consistent with the actual configuration, so that the configuration file can be updated in time, and avoids configuration file generation errors.

[0123] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0124] Reference Figure 2 , shows a structural block diagram of a device for dynamically generating a configuration file provided by an embodiment of the present invention, which is applied to a switch, wherein the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an update process, and specifically may include the following modules:

[0125] Subscription module 201, used for the monitoring process to subscribe to the SNMP database table and monitor the changes of key values ​​in the database table; the key values ​​include VRF key-value pairs and IP address key-value pairs;

[0126] A receiving module 202, configured for the monitoring process to receive a netlink message sent by the switch kernel, wherein the netlink message includes an IP address change message and a virtual routing forwarding VRF change message;

[0127] The sending module 203 is used for, if the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request of the SNMP configuration file to the update process;

[0128] The updating module 204 is used to determine whether the configuration file needs to be updated after the updating process receives the updating request, and update the configuration file if the configuration file needs to be updated.

[0129] In an optional embodiment, the database includes multiple IP addresses, and the sending module 203 includes:

[0130] A first judgment submodule, configured to judge whether the IP address exists in the database when the netlink message is a change of the IP address;

[0131] The first sending submodule is used for, if the IP address exists in the database, the monitoring process sending an update request for the SNMP configuration file to the update process.

[0132] In an optional embodiment, the IP address includes a valid IP address, and the updating module 204 includes:

[0133] The first update submodule is used for, if the IP address is a valid IP address and the change of the IP address is deletion or addition of the IP address, the update process generates a configuration file for deleting or adding the IP address, and updates the SNMP configuration file according to the configuration file for deleting or adding the IP address.

[0134] In an optional embodiment, the database further includes a plurality of VRFs, and the sending module 203 includes:

[0135] A second judgment submodule is used to judge whether the port name of the VRF interface exists in the database if the netlink message is a change of the VRF;

[0136] The second sending submodule is used for, if the VRF exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

[0137] In an optional embodiment, the VRF includes a valid VRF, and the updating module 204 includes:

[0138] The second update submodule is used for, if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, the update process generates a configuration file for deleting or adding the VRF, and updates the SNMP configuration file according to the configuration file for deleting or adding the VRF.

[0139] In an optional embodiment, it also includes:

[0140] The exclusive lock acquisition module is used to acquire a file lock to exclusively own the configuration file and perform a write operation or a read operation when the update process receives multiple update requests from the monitoring process and updates the configuration file during the operation of the switch.

[0141] In an optional embodiment, the file lock stores an identifier of an updating process being used, and the device further comprises:

[0142] The judgment module is used to judge whether the file lock has the identifier when one of the multiple update processes requests the file lock permission; if it has the identifier, query whether the update process that exclusively occupies the file lock is alive; if it is alive, wait for the update process that exclusively occupies the file lock to release the file lock.

[0143] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0144] An embodiment of the present invention further provides a switch, including:

[0145] The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, each process of the above-mentioned method embodiment for dynamically generating a configuration file is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0146] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the above-mentioned method embodiment for dynamically generating a configuration file is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0147] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0148] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0149] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0150] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0151] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0152] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0153] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0154] The above is a detailed introduction to a method for dynamically generating a configuration file, a corresponding device for dynamically generating a configuration file, a switch and a computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principle and implementation mode of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for a person skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation mode and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A method for dynamically generating configuration files, It is characterized in that Applied to a switch, the switch is configured with a simple network management protocol SNMP, the switch runs a monitoring process and an update process, and the method includes: The monitoring process subscribes to the SNMP database table and monitors changes in key values ​​in the database table; the key values ​​include virtual routing forwarding VRF key-value pairs and IP address key-value pairs; The monitoring process receives a netlink message sent by the switch kernel, wherein the netlink message includes an IP address change message and a VRF change message; If the key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process; After receiving the update request, the update process determines whether the configuration file needs to be updated, and updates the configuration file if the configuration file needs to be updated.

2. The method according to claim 1, It is characterized in that The database includes a plurality of IP addresses, and if a key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request of the SNMP configuration file to the update process, including: In the case where the netlink message is a change of the IP address, determining whether the IP address exists in the database; If the IP address exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

3. The method according to claim 2, It is characterized in that The IP address includes a valid IP address. After receiving the update request, the update process determines whether the configuration file needs to be updated. If the configuration file needs to be updated, updating the configuration file includes: If the IP address is a valid IP address, and the change of the IP address is deletion or addition of the IP address, the update process generates a configuration file for deleting or adding the IP address, and updates the SNMP configuration file based on the configuration file for deleting or adding the IP address.

4. The method according to claim 1, It is characterized in that The database further includes a plurality of VRFs, and if a key value in the database table changes, and / or a change message of the IP address and / or a change message of the VRF is received, the monitoring process sends an update request for the SNMP configuration file to the update process, including: If the netlink message is a change of the VRF, determining whether the port name of the VRF interface exists in the database; If the VRF exists in the database, the monitoring process sends an update request for the SNMP configuration file to the update process.

5. The method according to claim 4, It is characterized in that The VRF includes a valid VRF, and after receiving the update request, the update process determines whether the configuration file needs to be updated, and if the configuration file needs to be updated, updates the configuration file, including: If the VRF is a valid VRF, and the change of the VRF is deletion or addition of the VRF, the update process generates a configuration file for deleting or adding the VRF, and updates the SNMP configuration file according to the configuration file for deleting or adding the VRF.

6. The method according to claim 1, It is characterized in that Also includes: During the operation of the switch, when the update process receives multiple update requests from the monitoring process and updates the configuration file, one of the multiple update processes acquires a file lock to exclusively occupy the configuration file and performs a write operation or a read operation.

7. The method according to claim 6, It is characterized in that The file lock stores an identifier of an updating process being used, and the method further comprises: When one of the update processes requests the file lock permission, determining whether the file lock has the identifier; If there is an identifier, query whether the update process that exclusively holds the file lock is alive; If it survives, wait for the update process that exclusively holds the file lock to release the file lock.

8. A device for dynamically generating a configuration file, It is characterized in that Applied to a switch, the switch is configured with a simple network management protocol SNMP, the switch runs a monitoring process and an update process, and the device includes: A subscription module, used for the monitoring process to subscribe to the SNMP database table and monitor changes in key values ​​in the database table; the key values ​​include VRF key-value pairs and IP address key-value pairs; A receiving module, used for the monitoring process to receive a netlink message sent by the switch kernel, wherein the netlink message includes an IP address change message and a virtual routing forwarding VRF change message; A sending module, configured to cause the monitoring process to send an update request for the SNMP configuration file to the update process if the key value in the database table changes and / or a change message of the IP address and / or a change message of the VRF is received; The updating module is used for determining whether the configuration file needs to be updated after the updating process receives the updating request, and updating the configuration file if the configuration file needs to be updated.

9. A switch, It is characterized in that include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method for dynamically generating a configuration file according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for dynamically generating a configuration file according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Network verification method and device

    CN111835532A

  • SDN network flow visualization method and device

    CN111953519A

  • System, method and equipment for configuring network time synchronization tool and medium

    CN115174374A

  • Method of simulating SNMP network element and performing network management system test with the network element

    CN1992635A

  • Network management apparatus and method based onsimple network management protocol

    KR1020060055243A