CN115941422A - Method, device, switch and storage medium for dynamically generating configuration file - Google Patents

Method, device, switch and storage medium for dynamically generating configuration file Download PDF

Info

Publication number
CN115941422A
CN115941422A CN202211282644.5A CN202211282644A CN115941422A CN 115941422 A CN115941422 A CN 115941422A CN 202211282644 A CN202211282644 A CN 202211282644A CN 115941422 A CN115941422 A CN 115941422A
Authority
CN
China
Prior art keywords
configuration file
vrf
address
snmp
updating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202211282644.5A
Other languages
Chinese (zh)
Other versions
CN115941422B (en
Inventor
刘威
郭巍松
陈翔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202211282644.5A priority Critical patent/CN115941422B/en
Publication of CN115941422A publication Critical patent/CN115941422A/en
Application granted granted Critical
Publication of CN115941422B publication Critical patent/CN115941422B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a method, a device, a switch and a storage medium for dynamically generating a configuration file, wherein the method is applied to the switch, the switch is configured with an SNMP and runs a monitoring process and an updating process, and the method comprises the following steps: the monitoring process subscribes a database table of the SNMP and monitors the change of key values in the database table; the monitoring process receives a netlink message sent by a switch kernel, wherein the netlink message comprises an IP address change message and a VRF change message; if the key value in the database table changes and/or receives the change message of the IP address and/or the change message of the VRF, the monitoring process sends an update request of the SNMP configuration file to the update process; and the updating process judges whether to update the configuration file according to the updating request. The configuration file of the SNMP is ensured to be consistent with the actual configuration, so that the configuration file of the SNMP can be updated in time, and the configuration file of the SNMP is prevented from generating errors.

Description

Method, device, switch and storage medium for dynamically generating configuration file
Technical Field
The present invention relates to the field of simple network management protocol technology, and in particular, to a method for dynamically generating a configuration file, an apparatus for dynamically generating a configuration file, a switch, and a computer-readable storage medium.
Background
Simple Network Management Protocol (SNMP) is a Simple Network Management Protocol, which belongs to an application layer Protocol in TCP/IP five-layer Protocol and is used for Network Management.
When a user modifies monitoring configuration or changes configuration relations of Virtual Routing and Forwarding (VRF), ports and IP addresses in the SNMP switch, the configuration file of the SNMP switch needs to be updated. Currently, a netlink is used for monitoring configuration relation changes of a VRF, a port and an IP address, but the method has limitations, for example, when equipment is restarted, various services are prepared, when a process of a configuration file starts to run and detect configuration, the process of maintaining the IP address and the port is not started, and the configuration file is generated wrongly; when the process for maintaining the IP address and the VRF is started, the correct relationship of the port is written into the database, but the netlink message of the IP address or the VRF cannot be received, and the configuration file cannot be updated in time.
Disclosure of Invention
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 apparatus for dynamically generating a configuration file, a switch and a computer-readable storage medium, which overcome or at least partially solve the above problems.
In order to solve the above problems, 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 updating process, and the method includes:
the monitoring process subscribes a database table of the SNMP and monitors the change of key values in the database table; the key value comprises a VRF key value pair and an IP address key value pair;
the monitoring process receives a netlink message sent by the switch kernel, wherein the netlink message comprises a change message of an IP address and a change message of a Virtual Router 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 are/is received, the monitoring process sends an update request of the SNMP configuration file to the update process;
and after receiving the updating request, the updating process judges whether the configuration file needs to be updated or not, and updates the configuration file under the condition that the configuration file needs to be updated.
Optionally, 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, where the update request includes:
judging whether the IP address exists in the database or not under the condition that the netlink message is the change of the IP address;
and if the IP address exists in the database, the monitoring process sends an updating request of the configuration file of the SNMP to the updating process.
Optionally, the IP address includes an effective IP address, and the updating process determines whether the configuration file needs to be updated after receiving the update request, and updates the configuration file when the configuration file needs to be updated, including:
if the IP address is an effective IP address and the change of the IP address is deleting or adding the IP address, the updating process generates a configuration file for deleting or adding the IP address and updates the configuration file of the SNMP according to the configuration file for deleting or adding the IP address.
Optionally, 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 of the SNMP configuration file to the update process, where the update request includes:
if the netlink message is the change of the VRF, judging whether a port name of the VRF interface exists in the database;
and if the VRF exists in the database, the monitoring process sends an update request of the configuration file of the SNMP to the update process.
Optionally, the VRF includes a valid VRF, and the updating process determines whether the configuration file needs to be updated after receiving the update request, and updates the configuration file when the configuration file needs to be updated, including:
and if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, the updating process generates a configuration file for deleting or adding the VRF, and updates the configuration file of the SNMP according to the configuration file for deleting or adding the VRF.
Optionally, the method further comprises:
in the running process of the switch, when the updating process receives a plurality of updating requests of the monitoring process and updates the configuration file, one updating process in the plurality of updating processes acquires a file lock to monopolize the configuration file and performs writing operation or reading operation.
Optionally, wherein the file lock stores an identifier that an update process is being used, the method further comprises:
when one of the plurality of update processes requests file lock authority, determining whether the file lock has the identifier;
if the file lock has the identifier, inquiring whether an updating process exclusive to the file lock is alive;
and if the file lock is alive, waiting for the updating process which monopolizes the file lock to release the file lock.
The embodiment of the invention discloses a device for dynamically generating configuration files, which is applied to a switch, wherein the switch is configured with a Simple Network Management Protocol (SNMP), a monitoring process and an updating process run on the switch, and the device comprises:
the subscription module is used for subscribing the database table of the SNMP by the monitoring process and monitoring the change of key values in the database table; the key value comprises a VRF key value pair and an IP address key value pair;
a receiving module, configured to receive, by the monitoring process, a netlink message sent by the switch core, where the netlink message includes a change message of an IP address and a change message of a virtual router forwarding VRF;
a sending module, configured to send, by the monitoring process, an update request of the SNMP configuration file to the update process 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;
and the updating module is used for judging whether the configuration file needs to be updated or not after the updating process receives the updating request, and updating the configuration file under the condition that the configuration file needs to be updated.
Optionally, the database includes a plurality of IP addresses, and the sending module includes:
a first judging sub-module configured to judge whether the IP address exists in the database, when the netlink message is a change of the IP address;
and the first sending submodule is used for sending an updating request of the configuration file of the SNMP to the updating process by the monitoring process if the IP address exists in the database.
Optionally, the IP address includes a valid IP address, and the updating module includes:
and the first updating submodule is used for generating a configuration file for deleting or adding the IP address by the updating process if the IP address is an effective IP address and the change of the IP address is to delete or add the IP address, and updating the configuration file of the SNMP according to the configuration file for deleting or adding the IP address.
Optionally, the database further comprises a plurality of the VRFs, and the sending module comprises:
a second judging submodule, configured to judge whether a port name of the VRF interface exists in the database if the netlink message is a change of the VRF;
a second sending submodule, configured to send, by the monitoring process, an update request of the SNMP configuration file to the update process if the VRF exists in the database
Optionally, the VRF comprises a valid VRF, the update module comprising:
and the second updating submodule is used for generating a configuration file for deleting or adding the VRF if the VRF is a valid VRF and the change of the VRF is deleting or adding the VRF, and updating the configuration file of the SNMP according to the configuration file for deleting or adding the VRF.
Optionally, the method further comprises:
and the exclusive lock acquisition module is used for acquiring a file lock exclusive to the configuration file by one of the plurality of updating processes and performing write operation or read operation when the updating process receives a plurality of updating requests of the monitoring process and updates the configuration file in the running process of the switch.
Optionally, the file lock stores an identifier that an update process is being used, the apparatus further comprising:
the judging module is used for judging whether the file lock has the identifier or not when one updating process of the plurality of updating processes requests the file lock right; if the file lock has the identifier, inquiring whether an updating process exclusive to the file lock is alive; and if the file lock is alive, waiting for the updating process which monopolizes the file lock to release the file lock.
The embodiment of the invention also discloses an electronic device, which comprises: a processor, a memory and a computer program stored on the memory and being executable on the processor, the computer program, when executed by the processor, implementing the steps of the method of dynamically generating a profile as described above.
The embodiment of the invention also discloses a computer readable storage medium, wherein a computer program is stored on the computer readable storage medium, and when the computer program is executed by a processor, the steps of the method for dynamically generating the configuration file are realized.
The embodiment of the invention has the following advantages:
in the embodiment of the invention, a monitoring process subscribes a database table of SNMP and monitors the change of key values in the database table; the key value comprises a VRF key value pair and an IP address key value pair; the monitoring process receives a netlink message sent by a switch kernel, wherein the netlink message comprises a change message of an IP address and a change message of a virtual router forwarding VRF; if the key value in the database table changes and/or receives the change message of the IP address and/or the change message of the VRF, the monitoring process sends an update request of the SNMP configuration file to the update process; and after receiving the updating request, the updating process judges whether the configuration file needs to be updated or not, and updates the configuration file under the condition that the configuration file needs to be updated. Therefore, the configuration file of the SNMP is ensured to be consistent with the actual configuration, the configuration file of the SNMP can be updated in time, and the configuration file generation error of the SNMP is avoided.
Drawings
FIG. 1 is a flowchart illustrating steps of a method for dynamically generating a configuration file according to an embodiment of the present invention;
fig. 2 is a block diagram of a structure of an apparatus for dynamically generating a configuration file according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Simple Network Management Protocol (SNMP), a network protocol used to manage and monitor network connected devices in an Internet protocol network.
The SNMP technique is a method for automatically helping an administrator to collect network operation conditions by using an SNMP protocol in large-scale network management, and helps the network administrator to know the operation conditions of network equipment which is not around in real time. By this method, the network administrator can know the operation of the network equipment of the whole company only by sitting at the position of the network administrator. With this simple Network Management protocol, a Network administrator can exchange Management information between an SNMP Agent (Agent) and an SNMP Management Station (NMS) very conveniently.
1. SNMP has the following advantages:
1) Automated network management. Network administrators can utilize the SNMP platform to retrieve information, modify information, discover faults, complete fault diagnostics, perform capacity planning, and generate reports on the nodes on the network.
2) The physical difference of different devices is shielded, and the automatic management of products of different manufacturers is realized. SNMP provides only the most basic set of functions, making the management tasks relatively independent of the physical characteristics of the managed devices and the underlying networking technologies, respectively, thereby enabling management of devices of different vendors, and being particularly suitable for use in small, fast, and low-cost environments.
2. SNMP working mechanism
The SNMP network elements are divided into NMS and Agent.
1) The NMS (Network Management Station) is a workstation for running an SNMP client program, and can provide a very friendly man-machine interface, thereby facilitating a Network administrator to complete most Network Management work.
2) An Agent is a process residing on a device and is responsible for receiving and processing request messages from the NMS. In some emergency situations, such as a change in interface status, the Agent may also actively notify the NMS.
3) The NMS is the manager of the SNMP network, and the Agent is the managed party of the SNMP network. The NMS and the Agent interact management information through an SNMP protocol.
4) SNMP provides four basic operations:
get operation: the NMS queries the value of one or more objects of the Agent using this operation.
Set operation: the NMS uses this operation to reset the values of one or more objects in an Agent database (MIB).
Trap operation: the Agent uses this operation to send alarm information to the NMS.
The Inform operation: the NMS uses this operation to send alarm information to other NMSs.
Netlink is an IPC (Inter Process communication) mechanism, which is a mechanism for kernel-to-user space communication, and also for Inter-Process communication (Netlink is more used for kernel communication, and Inter-Process communication is more used for Unix domain sockets).
Virtual Routing and Forwarding (VRF), a route on the same device may be divided into different groups, and then the route is forwarded according to a requested interface and a destination address.
In the embodiment of the invention, the SNmpd process can be operated in the SNMP switch, the SNmpd process can be an updating process, and various information can be disclosed by using an SNMP protocol.
The Snmpd-conf is a configuration file of the SNMP and defines the network address and the port number monitored by the process of the SNMP.
The SNMP process is a part of an actual network device for implementing the SNMP function. Generally, the SNMP process receives the NMS read-write request message at the 161 port of UDP and the management station receives the agent's event notification message at the 162 port of UDP. So once the access rights of the device are obtained, the device information can be accessed, the device parameters can be rewritten and configured.
When a user modifies an IP address or modifies a configuration relationship between a port and a VRF, the configuration file cannot be updated in time when equipment is restarted in the conventional mode of monitoring the change of the IP address and the change of the VRF, so that the generation of the configuration file is wrong, and after the modified configuration relationship is written into a database, the configuration file cannot be updated in time because Netlink messages modified by the configuration relationship between the IP address or the modified port and the VRF cannot be received.
One of the core ideas of the embodiment of the invention is that a monitoring process is operated to subscribe a database table to monitor the change of the key value of the database table, meanwhile, the change of the IP address and the VRF is monitored through Netlink, when the change of the key value of the database table and/or the change of the IP address and/or the VRF are monitored, a request for updating the configuration file can be sent to the updating process in time, the updating process judges whether the update is needed according to the updating request, and the configuration file is updated under the condition that the update is needed. Therefore, the configuration file of the SNMP is ensured to be consistent with the actual configuration, the configuration file can be updated in time, and the configuration file generation error is avoided.
Referring to fig. 1, a flowchart of steps of a method for dynamically generating a configuration file according to an embodiment of the present invention is shown, where the method is applied to a switch, the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an updating process, and the method specifically includes the following steps:
step 101, the monitoring process subscribes a database table of the SNMP and monitors the change of key values in the database table; the key values include a VRF key-value pair and an IP address key-value pair.
In the embodiment of the invention, the database table subscribing the SNMP can be started when monitoring is started, and the change of key values in the database table is monitored through the database table subscribing the SNMP, wherein the key values can comprise VRF key value pairs and IP address key value pairs.
As an example, the SNMP database may be a key-value store (key-value store), which is mainly used in the case where all database accesses are operated by primary keys (primary keys), for which the basic data model is the key-value model. The key (key) is a String type and the value (value) is a basic data type, e.g., string, integer, etc. The key-value database may perform a new write or update of a key-value pair, read the corresponding value according to a key, and delete the entire key-value peer according to a key.
For example, the client may set a value corresponding to a key or delete a key from the database according to the key query value. An application may provide a key and a value and persist the key-value pair. If the key already exists, the current value is overwritten with the new value, otherwise a piece of data is created.
As an example, a change in key value in a key may be monitored by indicating which key in which database is used, for example, MGMT _ VRF _ CONFIG key in a configuration database (CONFIG-db) indicating whether a management port of a device is added to a network management port (MGMT), using a subscriber status table function.
For example, one key in the database table of the SNMP is VRF, the key value is VRF1, and when a user newly creates a VRF2, the monitoring process monitors that the key value of the database changes.
Step 102, the monitoring process receives a netlink message sent by the switch kernel, where the netlink message includes a change message of an IP address and a change message of a virtual router forwarding VRF.
Illustratively, the snooping process may receive a netlink message sent by the switch kernel, where the netlink message may be a change message of an IP address or a change message of a VRF.
As an example, a user may divide different ports into different VRF interfaces, and a VRF interface may have multiple hardware ports, and a hardware port may belong to only one VRF interface.
As an example, when a user modifies an IP address, the kernel may send a netlink message of the IP address change to the listening process.
As an example, when a user modifies a port, the VRF's relationship to the port changes, and the kernel can send a netlink message of the VRF change to the listening process.
Step 103, 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 are received, the monitoring process sends an update request of the SNMP configuration file to the update process.
Illustratively, when a key value in a database table changes, a monitoring process is triggered to send a request for updating the configuration file to an updating process of the configuration file; and when receiving the change message of the IP address and/or the change message of the VRF, triggering the monitoring process to send a request for updating the configuration file to an updating process of the configuration file.
As one example, the change in key values may include additions or deletions to VRF key-value pairs in a database table.
In an embodiment of the present invention, the database includes a plurality of IP addresses, and the sending, by the monitoring process, an update request of the configuration file of the SNMP switch to the update process 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 includes: judging whether the IP address exists in the database or not under the condition that the netlink message is the change of the IP address; and if the IP address exists in the database, the monitoring process sends an updating request of the configuration file of the SNMP to the updating process.
In the embodiment of the invention, the database of the SNMP can comprise a plurality of IP addresses, and the IP addresses in the database are all related to the SNMP.
Illustratively, the change of the IP address may include an addition of the IP address and a deletion of the IP address. When receiving a netlink message with a changed IP address, judging whether a corresponding IP address exists in a database or not, if so, indicating that the changed IP address is the IP address of the SNMP, and triggering a monitoring process to send a request for updating the configuration file of the SNMP to an updating process; if the corresponding IP address does not exist, the changed IP address is not the IP address of the SNMP, and the monitoring process is not triggered to send a request for updating the configuration file of the SNMP to the updating process.
In an embodiment of the present invention, the database further includes a plurality of VRFs, and the sending, by the monitoring process, an update request of the SNMP configuration file to the update process 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 includes: if the netlink message is the change of the VRF, judging whether a port name of the VRF interface exists in the database; and if the VRF exists in the database, the monitoring process sends an updating request of the configuration file of the SNMP to the updating process.
In the embodiment of the invention, the database of the SNMP can comprise a plurality of VRFs, and the VRFs in the database are all related to the SNMP. Each VRF in the database comprises a plurality of ports, and each port corresponds to an IP address.
Illustratively, a change in VRF may refer to a change in the relationship of the VRF to a port, such as adding or deleting a VRF, which changes in correspondence. When receiving a netlink message with a VRF change, firstly judging whether a corresponding VRF exists in a database, if so, indicating that the VRF with the change is a VRF of SNMP, and triggering a monitoring process to send a request for updating a configuration file of the SNMP to an updating process; if the corresponding VRF does not exist, the changed VRF is not the VRF of the SNMP, and the monitoring process is not triggered to send a request for updating the configuration file of the SNMP to the updating process.
In the embodiment of the invention, the two processes are respectively responsible for different function realization to complete the updating of the configuration file, each process is responsible for a single function task, the function coupling among the processes is not strong, compared with the method that one process finishes all the tasks, the method adopts two processes which focus on different functions, the multiplexing is convenient, and the verbosity and the complexity in the function realization process are reduced.
And step 104, after receiving the update request, the update process judges whether the configuration file needs to be updated, and updates the configuration file when the configuration file needs to be updated.
Illustratively, when the update process receives an update request, it may check to determine whether the configuration file needs to be updated, and in the case that the configuration file needs to be updated, update the configuration file of the SNMP.
For example, a user may newly create a VRF in the command line and allocate a corresponding port to the VRF, the database may newly add a VRF and a port number according to the command, the monitor process may determine whether the newly added VRF is a VRF related to the SNMP, and if so, may send an update request to the update process. The update process may generate a configuration file containing the newly added VRF after receiving the update request, and may update the original configuration file according to the newly generated configuration file.
In an embodiment of the present invention, the IP address includes an effective IP address, the updating process determines whether the configuration file needs to be updated after receiving the update request, and if the configuration file needs to be updated, updating the configuration file includes: if the IP address is an effective IP address and the change of the IP address is deleting or adding the IP address, the updating process generates a configuration file for deleting or adding the IP address and updates the configuration file of the SNMP according to the configuration file for deleting or adding the IP address.
In the embodiment of the invention, the SNMP database can comprise a plurality of IP addresses, and the plurality of IP addresses can be divided into effective IP addresses and invalid IP addresses.
As an example, when the update process determines that the deleted or added IP address is a valid IP address, a configuration file of the deleted or added IP address may be generated and the configuration file of the SNMP may be updated according to the configuration file of the deleted or added IP address.
As an example, the configuration file of SNMP may contain parameters such as IP address, VRF's relationship to port, etc. The VRF, the port and the IP address can be a list of associated data, and when the VRF or the IP address is added or deleted, the VRF, the port and the IP address can be simultaneously added or deleted.
For example, a user may add an IP address in a command window of a switch, a kernel of the switch may send a message of the IP address addition to a monitoring process through a netlink, the monitoring process receives the netlink message of the IP address addition, determines whether the added IP address exists in a database of an SNMP, sends a request for updating a configuration file to an updating process in the case that the added IP address exists in the database of the SNMP, determines whether the added IP address is an effective IP address in the database of the SNMP after the updating process receives the request for updating the configuration file, does not update the IP address if the added IP address is not an effective IP address, generates a configuration file including a newly added IP address if the added IP address is an effective IP address, and updates an original configuration file according to the configuration file including the newly added IP address.
For example, a user may delete an IP address in a command window of the switch, the kernel of the switch may send a message for deleting the IP address to the monitoring process through a netlink, the monitoring process determines whether the deleted IP address exists in the SNMP database after receiving the netlink message for deleting the IP address, sends a request for updating the configuration file to the updating process in the case that the deleted IP address exists in the SNMP database, determines whether the deleted IP address is an effective IP address in the SNMP database after the updating process receives the request for updating the configuration file, does not update the IP address if the deleted IP address is not an effective IP address, generates a configuration file including the deleted IP address if the deleted IP address is an effective IP address, and updates the original configuration file according to the configuration file including the deleted IP address.
In the embodiment of the invention, the configuration file can be updated in the process when the changed IP address is the effective IP address in the database, and the configuration file is not updated when the changed IP address is the ineffective IP address, so that unnecessary operation is reduced, blind update is avoided, and the storage space of the equipment is increased.
In an embodiment of the present invention, the VRF of the SNMP switch includes a valid VRF, the update process determines whether the configuration file needs to be updated after receiving the update request, and if the configuration file needs to be updated, updating the configuration file includes: and if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, the updating 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.
Illustratively, in the embodiment of the present invention, the SNMP database may include a plurality of VRFs, and the plurality of VRFs may be divided into valid VRFs and invalid VRFs.
As an example, when the update process determines that the deleted or added VRF is a valid VRF, a configuration file of the deleted or added VRF may be generated and the configuration file of the SNMP may be updated according to the configuration file of the deleted or added VRF.
As an example, when a user can delete or add a VRF through a command line in the switch, the database changes the value of the VRF in the database according to the command of deleting or adding the VRF issued by the command line.
As an example, the configuration file of SNMP may contain parameters such as IP address, VRF-port relationship, etc. The VRF, the port and the IP address can be a list of associated data, and when the VRF or the IP address is added or deleted, the VRF, the port and the IP address can be simultaneously added or deleted.
For example, a user may delete a VRF in a command window of the switch, a kernel of the switch may send a message for deleting the VRF to the monitoring process through a netlink, the monitoring process receives the message for deleting the VRF through the netlink, and determines whether the deleted VRF exists in the SNMP database, and requests the update process to update the configuration file when the deleted VRF exists in the SNMP database; and after receiving a request for updating the configuration file, the updating process judges whether the deleted VRF is a valid VRF in the database, if not, does not update the VRF, and if so, generates the configuration file containing the deleted VRF, and updates the original configuration file according to the configuration file containing the deleted VRF.
For example, a user may newly create a VRF in a command window of a switch, and allocate a port to the newly created VRF, a kernel of the switch may send a message of VRF addition to a monitoring process through a netlink, the monitoring process receives the message of VRF addition through the netlink, and determines whether the added VRF exists in a database of an SNMP, and requests an update process to update a configuration file if the added VRF exists in the database; and after receiving a request for updating the configuration file, the updating process judges whether the added VRF is a valid VRF in the database, if not, does not update the VRF, and if so, generates the configuration file containing the added VRF and updates the original configuration file according to the configuration file containing the added VRF.
In the embodiment of the invention, the configuration file can be updated in the process when the changed VRF is the effective VRF in the database, and the configuration file can not be updated when the changed VRF is the ineffective VRF, thereby reducing unnecessary operation, avoiding blind update and increasing the storage space of equipment.
In an embodiment of the present invention, in an operation process of the switch, when the update process receives multiple update requests of the monitoring process and updates the configuration file, one update process of the multiple update processes acquires a file lock to exclusively occupy the configuration file, and performs a write operation or a read operation.
As an example, when a listening process sends multiple update requests to an update process at the same time, and a corresponding plurality of update processes perform read operation or write operation on a configuration file, a contention problem may occur, for example, the read operation and the write operation are performed at the same time, or when a plurality of update processes perform write operation at the same time, a configuration file update error may be caused by the problem of contention on the configuration file.
As an example, to avoid multiple update processes reading and/or writing to the same configuration file at the same time, a file lock may be requested to grant permission when preparing to read or write to a file.
For example, the update process includes an update process 1, an update process 2, and an update process 3, where the update process 1 performs write operation on the configuration file, the update process 2 performs read operation on the configuration file, and the update process 3 performs write operation on the configuration file, and the three processes perform operations simultaneously, so that the update process 1 may first acquire a file lock, monopolize the configuration file, and perform write operation, and the update process 2 and the update process 3 wait in a queue, and after the update process 1 completes the write operation, release the file lock; the updating process 2 acquires the file lock again, monopolizes the configuration file for reading operation, and releases the file lock after the updating process 2 finishes writing operation; and the updating process 3 acquires the file lock again, monopolizes the configuration file to perform read operation until the updating process 3 finishes write operation, and releases the file lock, so that the updating of the configuration file is finished, and the configuration file updating error caused by the problem of contention for the configuration file is avoided.
In one embodiment of the present invention, when the monitor process generates multiple update requests, repeated update requests are filtered, and the filtered update requests are sent to the update process.
For example, when the listening process generates multiple update requests, repeated update requests may be filtered, and then the filtered update requests may be sent to the update process, so as to increase the operating speed of the device.
In one embodiment of the invention, the file lock stores an identifier that an update process is being used, the method further comprising: when one of the plurality of updating processes requests the file lock right, judging whether the file lock has the identifier; if the file lock has the identifier, inquiring whether an updating process exclusive to the file lock is alive; and if the file lock exists, waiting for the updating process monopolizing the file lock to release the file lock.
As an example, a file lock may store an identifier of an updating process being used, and when an updating process of a plurality of updating processes requests a file lock right, it may be determined whether the file lock has an identifier of a process; if the file lock has the identifier, inquiring whether the updating process monopolizing the file lock is alive or not; if the file lock exists, the file lock is released by the process which monopolizes the file lock, so that whether the process monopolizes the file lock can be effectively distinguished.
In the embodiment of the invention, the monitoring process subscribes to the database table of the SNMP and monitors the change of key values in the database table; the key value comprises a VRF key value pair and an IP address key value pair; the monitoring process receives a netlink message sent by the switch kernel, wherein the netlink message comprises a change message of an IP address and a change message of a virtual router forwarding VRF; if the key value in the database table changes and/or receives the change message of the IP address and/or the change message of the VRF, the monitoring process sends an update request of the SNMP configuration file to the update process; and after receiving the updating request, the updating process judges whether the configuration file needs to be updated or not, and updates the configuration file under the condition that the configuration file needs to be updated. Therefore, the configuration file of the SNMP is ensured to be consistent with the actual configuration, the configuration file can be updated in time, and the configuration file generation error is avoided.
It should be noted that for simplicity of description, the method embodiments are shown as a series of combinations of acts, but those skilled in the art will recognize that the embodiments are not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments. Further, those of skill in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the embodiments of the invention.
Referring to fig. 2, a block diagram of a structure of a device for dynamically generating a configuration file according to an embodiment of the present invention is shown, and is applied to a switch, where the switch is configured with a simple network management protocol SNMP, and the switch runs a monitoring process and an updating process, and specifically includes the following modules:
a subscription module 201, configured to subscribe the SNMP database table by the monitoring process, and monitor a change of a key value in the database table; the key value comprises a VRF key value pair and an IP address key value pair;
a receiving module 202, configured to receive, by the monitor process, a netlink message sent by the switch kernel, where the netlink message includes a change message of an IP address and a change message of a virtual router forwarding VRF;
a sending module 203, configured to send, by the monitoring process, an update request of the SNMP configuration file to the update process 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;
an updating module 204, configured to determine whether the configuration file needs to be updated after the updating process receives the update request, and update the configuration file when the configuration file needs to be updated.
In an alternative embodiment, the database includes a plurality of IP addresses, and the sending module 203 includes:
a first judging sub-module configured to judge whether the IP address exists in the database, when the netlink message is a change of the IP address;
and the first sending submodule is used for sending an updating request of the configuration file of the SNMP to the updating process by the monitoring process if the IP address exists in the database.
In an alternative embodiment, the IP address includes a valid IP address, and the update module 204 includes:
and the first updating submodule is used for generating a configuration file for deleting or adding the IP address by the updating process if the IP address is an effective IP address and the change of the IP address is to delete or add the IP address, and updating the configuration file of the SNMP according to the configuration file for deleting or adding the IP address.
In an alternative embodiment, the database further comprises a plurality of the VRFs, and the sending module 203 comprises:
a second judging submodule, configured to judge whether a port name of the VRF interface exists in the database if the netlink message is a change of the VRF;
a second sending submodule, configured to send, by the monitoring process, an update request of the SNMP configuration file to the update process if the VRF exists in the database
In an alternative embodiment, the VRFs include valid VRFs, and the update module 204 includes:
and the second updating submodule is used for generating a configuration file for deleting or adding the VRF by the updating process if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, and updating the configuration file of the SNMP according to the configuration file for deleting or adding the VRF.
In an optional embodiment, further comprising:
and the exclusive lock acquiring module is used for acquiring a file lock exclusive to the configuration file by one of the plurality of updating processes to perform write operation or read operation when the updating processes receive a plurality of updating requests of the monitoring process and update the configuration file in the running process of the switch.
In an alternative embodiment, the file lock stores an identifier that an update process is being used, the apparatus further comprising:
the judging module is used for judging whether the file lock has the identifier or not when one updating process of the plurality of updating processes requests the file lock right; if the file lock has the identifier, inquiring whether an updating process exclusive to the file lock is alive; and if the file lock is alive, waiting for the updating process which monopolizes the file lock to release the file lock.
For the apparatus embodiment, since it is substantially similar to the method embodiment, the description is relatively simple, and reference may be made to the partial description of the method embodiment for relevant points.
An embodiment of the present invention further provides a switch, including:
the method comprises a processor, a memory and a computer program which is stored in the memory and can run on the processor, wherein when the computer program is executed by the processor, each process of the method embodiment for dynamically generating the configuration file is realized, the same technical effect can be achieved, and in order to avoid repetition, the description is omitted here.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when being executed by a processor, the computer program implements each process of the above method for dynamically generating a configuration file, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "include", "including" or any other variations 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 inherent to such process, method, article, or terminal device. Without further limitation, an element defined by the phrases "comprising one of \ 8230; \8230;" does not exclude the presence of additional like elements in a process, method, article, or terminal device that comprises the element.
The method for dynamically generating a configuration file, the corresponding device for dynamically generating a configuration file, the switch and the computer-readable storage medium provided by the present invention are described in detail above, and a specific example is applied in the present document to explain the principle and the embodiment of the present invention, and the description of the above embodiment is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (10)

1. A method for dynamically generating a configuration file is applied to a switch, the switch is configured with a Simple Network Management Protocol (SNMP), the switch runs with a monitoring process and an updating process, and the method comprises the following steps:
the monitoring process subscribes a database table of the SNMP and monitors the change of key values in the database table; the key value comprises a Virtual Router Forwarding (VRF) key value pair and an IP address key value pair;
the monitoring process receives a netlink message sent by the switch kernel, wherein the netlink message comprises a change message of an IP address and a change message of a VRF;
if the key value in the database table changes and/or receives the change message of the IP address and/or the change message of the VRF, the monitoring process sends an update request of the SNMP configuration file to the update process;
and after receiving the updating request, the updating process judges whether the configuration file needs to be updated or not, and updates the configuration file under the condition that the configuration file needs to be updated.
2. The method according to claim 1, wherein the database includes a plurality of IP addresses, and the sending, by the listening process, an update request for the SNMP configuration file to the update process if a key value in the database table changes and/or a change message for the IP address and/or a change message for the VRF is received comprises:
judging whether the IP address exists in the database or not under the condition that the netlink message is the change of the IP address;
and if the IP address exists in the database, the monitoring process sends an updating request of the configuration file of the SNMP to the updating process.
3. The method according to claim 2, wherein the IP address includes a valid IP address, the updating process determines whether the configuration file needs to be updated after receiving the update request, and if the configuration file needs to be updated, updating the configuration file comprises:
if the IP address is an effective IP address and the change of the IP address is deleting or adding the IP address, the updating process generates a configuration file for deleting or adding the IP address and updates the configuration file of the SNMP according to the configuration file for deleting or adding the IP address.
4. The method according to claim 1, wherein the database further includes a plurality of VRFs, and the sending, by the listening process, an update request for the SNMP configuration file to the update process if a key value in the database table changes and/or a change message for the IP address and/or a change message for the VRF is received comprises:
if the netlink message is the change of the VRF, judging whether a port name of the VRF interface exists in the database;
and if the VRF exists in the database, the monitoring process sends an update request of the configuration file of the SNMP to the update process.
5. The method according to claim 4, wherein the VRF comprises a valid VRF, and wherein the updating process determines whether the configuration file needs to be updated after receiving the update request, and updates the configuration file if the configuration file needs to be updated, comprising:
and if the VRF is a valid VRF and the change of the VRF is to delete or add the VRF, the updating process generates a configuration file for deleting or adding the VRF, and updates the configuration file of the SNMP according to the configuration file for deleting or adding the VRF.
6. The method of claim 1, further comprising:
in the running process of the switch, when the updating process receives a plurality of updating requests of the monitoring process and updates the configuration file, one updating process in the plurality of updating processes acquires a file lock to monopolize the configuration file and performs writing operation or reading operation.
7. The method of claim 4, wherein the file lock stores an identifier that an update process is being used, the method further comprising:
when one of the plurality of update processes requests file lock authority, determining whether the file lock has the identifier;
if the file lock has the identifier, inquiring whether an updating process exclusive to the file lock is alive;
and if the file lock is alive, waiting for the updating process which monopolizes the file lock to release the file lock.
8. An apparatus for dynamically generating a configuration file, applied to a switch, wherein the switch is configured with a Simple Network Management Protocol (SNMP), the switch runs with a monitoring process and an updating process, and the apparatus comprises:
the subscription module is used for subscribing the database table of the SNMP by the monitoring process and monitoring the change of key values in the database table; the key value comprises a VRF key value pair and an IP address key value pair;
a receiving module, configured to receive, by the monitoring process, a netlink message sent by the switch core, where the netlink message includes a change message of an IP address and a change message of a virtual router forwarding VRF;
a sending module, configured to send, by the monitoring process, an update request of the SNMP configuration file to the update process 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;
and the updating module is used for judging whether the configuration file needs to be updated or not after the updating process receives the updating request, and updating the configuration file under the condition that the configuration file needs to be updated.
9. A switch, comprising: processor, memory and a computer program stored on the memory and being executable on the processor, the computer program, when executed by the processor, implementing the steps of the method of dynamically generating a profile as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of dynamically generating a configuration file according to any one of claims 1 to 7.
CN202211282644.5A 2022-10-19 2022-10-19 Method, device, switch and storage medium for dynamically generating configuration file Active CN115941422B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211282644.5A CN115941422B (en) 2022-10-19 2022-10-19 Method, device, switch and storage medium for dynamically generating configuration file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211282644.5A CN115941422B (en) 2022-10-19 2022-10-19 Method, device, switch and storage medium for dynamically generating configuration file

Publications (2)

Publication Number Publication Date
CN115941422A true CN115941422A (en) 2023-04-07
CN115941422B CN115941422B (en) 2024-10-22

Family

ID=86699597

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211282644.5A Active CN115941422B (en) 2022-10-19 2022-10-19 Method, device, switch and storage medium for dynamically generating configuration file

Country Status (1)

Country Link
CN (1) CN115941422B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20060055243A (en) * 2004-11-18 2006-05-23 삼성전자주식회사 Network management apparatus and method based on simple network management protocol
CN1992635A (en) * 2005-12-27 2007-07-04 中兴通讯股份有限公司 Method of simulating SNMP network element and performing network management system test with the network element
US20090185494A1 (en) * 2006-12-27 2009-07-23 Li Jijun Redirector, relay, system for configuring route information and method for updating route information
CN111835532A (en) * 2019-04-11 2020-10-27 华为技术有限公司 Network authentication method and device
CN111953519A (en) * 2020-07-14 2020-11-17 浪潮思科网络科技有限公司 SDN network flow visualization method and device
CN115174374A (en) * 2022-06-30 2022-10-11 苏州浪潮智能科技有限公司 System, method, device and medium for configuring network time synchronization tool

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20060055243A (en) * 2004-11-18 2006-05-23 삼성전자주식회사 Network management apparatus and method based on simple network management protocol
CN1992635A (en) * 2005-12-27 2007-07-04 中兴通讯股份有限公司 Method of simulating SNMP network element and performing network management system test with the network element
US20090185494A1 (en) * 2006-12-27 2009-07-23 Li Jijun Redirector, relay, system for configuring route information and method for updating route information
CN111835532A (en) * 2019-04-11 2020-10-27 华为技术有限公司 Network authentication method and device
CN111953519A (en) * 2020-07-14 2020-11-17 浪潮思科网络科技有限公司 SDN network flow visualization method and device
CN115174374A (en) * 2022-06-30 2022-10-11 苏州浪潮智能科技有限公司 System, method, device and medium for configuring network time synchronization tool

Also Published As

Publication number Publication date
CN115941422B (en) 2024-10-22

Similar Documents

Publication Publication Date Title
JP3483364B2 (en) SNMP / OSI management gateway device
JP3489726B2 (en) How to manage network elements
US7401338B1 (en) System and method for an access layer application programming interface for managing heterogeneous components of a storage area network
JP4509916B2 (en) SNMP-based network management apparatus and method
US11463303B2 (en) Determining the health of other nodes in a same cluster based on physical link information
US20060041612A1 (en) Method and system for discovery of remote agents
CN101202751B (en) System and method for providing SNMP data for virtual networking devices
US20160092537A1 (en) Polling based synchronization in managed networks
MacFaden et al. Configuring networks and devices with simple network management protocol (snmp)
US6883024B2 (en) Method and apparatus for defining application scope and for ensuring finite growth of scaled distributed applications
EP1479192B1 (en) Method and apparatus for managing configuration of a network
US11689418B2 (en) Sharing configuration resources for network devices among applications
CN115941422A (en) Method, device, switch and storage medium for dynamically generating configuration file
WO2005088905A1 (en) A method for managing management information base in network managing system
Cisco Glossary
Cisco Glossary
Cisco Glossary
EP1649637B1 (en) Apparatus and method for managing traps in a network
Cisco Glossary
Cisco Glossary
Cisco Glossary
KR100441892B1 (en) Apparatus and method for integrally managing subscriber for CO-LAN
US20150149606A1 (en) Managed object manipulation
KR20190051627A (en) Operation layer improving apparatus and method of network configuration protocol in network management system
WO2023125308A1 (en) Configuration management method and apparatus, device, system, storage medium and program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant