A kind of method and system simulating the trap message of multiple network element
Technical field
The invention belongs to communication technical field, particularly relate to a kind of method and system simulating the trap message of multiple network element.
Background technology
SNMP (SimpleNetworkManagementProtocol, Simple Network Management Protocol) is one of NMP proposed the earliest, and due to its simplicity, it is widely used once releasing and supports.At present, SNMP has become the working stamndard in field of network management, and most of network management system and platform all realize based on snmp protocol.
Along with the extensive use of snmp protocol, so NSM (NetworkManagementSystem, network management system) network element that manages is thousands of, even hundreds thousand of, so in existing network applied environment, these network elements are at any time with producing warning information with carving, and send to NMS by Trap message, at this moment NMS must possess the ability of the Trap message simultaneously processing hundreds thousand of reported by network elements, therefore, in order to ensure carrying out smoothly of network management, when NMS comes into operation again, must test its performance.Agent (agency) on NMS and managed element carries out the uniting and adjustment stage, is often difficult to deployment large-scale test environment, except the problem such as fund, place also exists the problems such as the annexation of real network is intricate.Therefore, develop a set of analog simulation testing tool in the uniting and adjustment stage in the market and realize the performance test to network management system to replace various network element in actual environment.
But because snmp protocol belongs to application layer protocol, and according to TCP/IP (TransmissionControlProtocol/InternetProtocol, transmission control protocol/Internet Protocol) procotol stack mechanism, transport layer and following mechanism thereof are provided by kernel, application layer is provided by consumer process, and this analog simulation instrument operates in a PC (PersonalComputer, personal computer) on machine, therefore the IP head of network layer is assembled by the TCP/IP network protocol stack of kernel, Snmptrap (the trap message that managed devices reports sent, namely proactive notification when managed devices breaks down or changes) IP address in message is all identical, although so this analog simulation instrument can send Snmptrap message by analogue network element, but also can only simulate a network element and send Snmptrap message, and multiple network element can not be simulated to network management system transmission Snmptrap message simultaneously.Therefore, current analog simulation instrument has significant limitation, cannot test environment that is virtually reality like reality.For this problem, traditional solution utilizes the Variable-Bindings pair in Snmptrap message format, define privately owned definition message format, as specified, second Variable-Bindings in Snmptrap message is to the IP address representing network element, after NMS collects this message, resolve second Variable-Bindings pair, obtain the IP address of network element, then according to handling process process.The method also has certain limitation, essence or the Snmptrap message of a network element, really intactly cannot simulate the flow process of multiple network element transmitting-receiving snmp message.
To sum up, still there is the defect really cannot simulated multiple network element and network management system is tested in prior art.
Summary of the invention
The object of the embodiment of the present invention is to provide a kind of method and system simulating the trap message of multiple network element, be intended to solve in prior art exist really cannot simulate the problem that multiple network element tests network management system.
The embodiment of the present invention is achieved in that a kind of method simulating the trap message of multiple network element, comprising:
Read the configuration file of network under test management system, to obtain the configuration parameter of described network under test management system;
Receive and preserve the command parameter that user inputted by pseudo-terminal, read MAC Address and the IP address of described pseudo-terminal simultaneously, and generate MAC Address and the IP address of analogue network element according to the MAC Address of described command parameter and described pseudo-terminal and IP address according to pre-defined rule;
Rawsocket programming technique is adopted to assemble the Snmptrap message of described analogue network element according to the configuration parameter of described network under test management system and the MAC Address of described analogue network element and IP address;
Send function by rawsocket and described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
In the method for the trap message of the multiple network element of the simulation described in the embodiment of the present invention, the configuration file of described reading network under test management system, to obtain and the configuration parameter preserving described network under test management system specifically comprises:
Read the configuration file of described network under test management system, to obtain and to preserve the version number of the snmp protocol that the MAC Address of described network under test management system, IP address and described network under test management system adopt, community and Snmptrap Variable-Bindings pair.
In the method for the trap message of the multiple network element of the simulation described in the embodiment of the present invention, the MAC Address of the described pseudo-terminal of described reading and IP address, and generate the MAC Address of analogue network element according to the MAC Address of described command parameter and described pseudo-terminal and IP address according to pre-defined rule and IP address specifically comprises:
Needed for the input prompt information input user of described pseudo-terminal, the number of analogue network element and the cycle of analogue network element transmission Snmptrap message, read MAC Address and the IP address of described pseudo-terminal simultaneously;
With the number of analogue network element needed for user in described command parameter for the upper limit, with the MAC Address of described pseudo-terminal for plot, the cumulative MAC Address obtaining analogue network element, and the MAC Address of described analogue network element is saved in analogue network element information list;
With the number of analogue network element needed for user in described command parameter for the upper limit, with the IP address of described pseudo-terminal for plot, the cumulative IP address obtaining analogue network element, and the IP address of described analogue network element is saved in described analogue network element information list.
In the method for the trap message of the multiple network element of the simulation described in the embodiment of the present invention, the Snmptrap message that described employing rawsocket programming technique assembles described analogue network element according to the configuration parameter of described network under test management system and the MAC Address of described analogue network element and IP address specifically comprises:
Create rawsocket, and the option of socket in rawsocket is set, the IP packet header of the data that will send to make rawsocket manual handle;
The ETH head of the Snmptrap message of described analogue network element, IP head, UDP head and SNMP message body is assembled according to the MAC Address of analogue network element in the MAC Address of described network under test management system and IP address and described analogue network element information list and IP address.
In the method for the trap message of the multiple network element of the simulation described in the embodiment of the present invention, described by rawsocket send function described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message and specifically comprise:
The cycle of Snmptrap message is sent according to the described analogue network element of user's input, use described socketid that described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
Another object of the embodiment of the present invention is to provide a kind of system simulating the trap message of multiple network element, comprising:
Initialization module, for reading the configuration file of network under test management system, to obtain the configuration parameter of described network under test management system;
Act on behalf of generation module, for receiving and preserving the command parameter that user inputted by pseudo-terminal, read MAC Address and the IP address of described pseudo-terminal simultaneously, and generate MAC Address and the IP address of analogue network element according to the MAC Address of described command parameter and described pseudo-terminal and IP address according to pre-defined rule;
Depacketize module, assembles the Snmptrap message of described analogue network element for adopting rawsocket programming technique according to the configuration parameter of described network under test management system and the MAC Address of described analogue network element and IP address;
Message sending module, being sent to described network under test management system for sending function by rawsocket by described Snmptrap message, carrying out performance test to make described network under test management system according to described Snmptrap message.
In the system of the trap message of the multiple network element of the simulation described in the embodiment of the present invention, described initialization module specifically for:
Read the configuration file of described network under test management system, to obtain and to preserve the version number of the snmp protocol that the MAC Address of described network under test management system, IP address and described network under test management system adopt, community and Snmptrap Variable-Bindings pair.
In the system of the trap message of the multiple network element of the simulation described in the embodiment of the present invention, described generation module of acting on behalf of specifically comprises:
User input unit, for the number of analogue network element needed for the input prompt information input user of described pseudo-terminal and the cycle of analogue network element transmission Snmptrap message, reads MAC Address and the IP address of described pseudo-terminal simultaneously;
Analogue network element MAC Address generation unit, for with the number of analogue network element needed for user in described command parameter for the upper limit, with the MAC Address of described pseudo-terminal for plot, the cumulative MAC Address obtaining analogue network element, and the MAC Address of described analogue network element is saved in analogue network element information list;
Analogue network element IP scalar/vector, for with the number of analogue network element needed for user in described command parameter for the upper limit, with the IP address of described pseudo-terminal for plot, the cumulative IP address obtaining analogue network element, and the IP address of described analogue network element is saved in described analogue network element information list.
In the system of the trap message of the multiple network element of the simulation described in the embodiment of the present invention, described depacketize module specifically comprises:
Rawsocket unit, for creating rawsocket, and arranges the option of socket in rawsocket, the IP packet header of the data that will send to make rawsocket manual handle;
Module units, for assembling the ETH head of the Snmptrap message that described analogue network element sends, IP head, UDP head and SNMP message body according to the MAC Address of analogue network element in the MAC Address of described network under test management system and IP address and described analogue network element information list and IP address.
In the system of the trap message of the multiple network element of the simulation described in the embodiment of the present invention, described message sending module specifically comprises:
Socketid acquiring unit, for obtaining the socketid sending rawsocket;
Transmitting element, described analogue network element for inputting according to user sends the cycle of Snmptrap message, use described socketid that described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
The method and system implementing the trap message of the multiple network element of simulation that the embodiment of the present invention provides have following beneficial effect:
The embodiment of the present invention is owing to adopting rawsocket programming technique according to the configuration parameter of network under test management system and the Snmptrap message oneself assembling described analogue network element in advance according to the MAC Address of the analogue network element of pre-defined rule generation and IP address, thus user can be made to revise MAC Address in Snmptrap message and IP address, therefore, can realize really simulating multiple network element and send Snmptrap message to network under test management system, can be quick, networking test is carried out easily with network under test management system, the reliability and stability of effective inspection network under test management system.
Accompanying drawing explanation
Fig. 1 is the specific implementation flow chart of the method for the trap message of the multiple network element of simulation that the embodiment of the present invention provides;
Fig. 2 is the specific implementation flow chart of S102 in the method for the trap message of the multiple network element of simulation that the embodiment of the present invention provides;
Fig. 3 is the specific implementation flow chart of S103 in the method for the trap message of the multiple network element of simulation that the embodiment of the present invention provides;
Fig. 4 is the structured flowchart of the system of the trap message of the multiple network element of simulation that the embodiment of the present invention provides.
Embodiment
In order to make object of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
Fig. 1 shows the specific implementation flow process of the method for the trap message of the multiple network element of simulation that the embodiment of the present invention provides.Shown in Figure 1, the method for the trap message of the multiple network element of the simulation that the embodiment of the present invention provides, comprising:
In S101, read the configuration file of network under test management system, to obtain the configuration parameter of described network under test management system.
In embodiments of the present invention, first the configuration parameter of described network under test management system is known by user, described configuration parameter comprises MAC (MediaAccessControl, media interviews control) version number of the snmp protocol that adopts of address, IP address and described network under test management system, community and Snmptrap Variable-Bindings pair, then described configuration parameter to be written in the configuration file of described network under test management system and to preserve; The last configuration file being read described network under test management system by pseudo-terminal, to obtain and to preserve the version number of the snmp protocol that the MAC Address of described network under test management system, IP address and described network under test management system adopt, community and Snmptrap Variable-Bindings pair.
In S102, receive and preserve the command parameter that user inputted by pseudo-terminal, read MAC Address and the IP address of described pseudo-terminal simultaneously, and generate MAC Address and the IP address of analogue network element according to the MAC Address of described command parameter and described pseudo-terminal and IP address according to pre-defined rule.
Fig. 2 shows the specific implementation flow process of S102, and shown in Figure 2, S102 specifically comprises:
In S201, needed for the input prompt information input user of described pseudo-terminal, the number of analogue network element and the cycle of analogue network element transmission Snmptrap message, read MAC Address and the IP address of described pseudo-terminal simultaneously;
In S202, with the number of analogue network element needed for user in described command parameter for the upper limit, with the MAC Address of described pseudo-terminal for plot, the cumulative MAC Address obtaining analogue network element, and the MAC Address of described analogue network element is saved in analogue network element information list;
In S203, with the number of analogue network element needed for user in described command parameter for the upper limit, with the IP address of described pseudo-terminal for plot, the cumulative IP address obtaining analogue network element, and the IP address of described analogue network element is saved in described analogue network element information list.
In embodiments of the present invention, pseudo-terminal can be PC terminal, user can according to the number of the input prompt information of PC terminal by the KIS network element of PC terminal and the cycle of analogue network element transmission Snmptrap message, if the cycle that the analogue network element of user's input sends Snmptrap message is 0, then represent that this analogue network element uninterrupted circulation can send Snmptrap message to network under test management system.
In S103, rawsocket programming technique is adopted to assemble the Snmptrap message of described analogue network element according to the MAC Address of analogue network element described in the configuration parameter of described network under test management system and described analogue network element information list and IP address.
Fig. 3 shows the specific implementation flow process of S103, and shown in Figure 3, S103 specifically comprises:
In S301, create rawsocket, and the option of socket in rawsocket is set, the IP packet header of the data that will send to make rawsocket manual handle.
In embodiments of the present invention, directly use socket function creation rawsocket, then use setsockopt that the option of socket is set, the IP_HDRINCL in socket option is set to very, the IP packet header of the data that will send to make rawsocket manual handle.
In S302, assemble the ETH head of the Snmptrap message of described analogue network element, IP head, UDP head and SNMP message body according to the MAC Address of described network under test management system and the MAC Address of IP address and described analogue network element and IP address.
In embodiments of the present invention, the ETH head assembling the Snmptrap message of analogue network element specifically comprises: with the MAC Address of analogue network element in described analogue network element information list for source address, assemble the source MAC in described ETH head; Address for the purpose of the MAC Address of described network under test management system, assembles the target MAC (Media Access Control) address in described ETH head; Assemble the type field in described ETH head, be fixed as 0X0880, wherein 0X0880 represents that network layer protocol is IP agreement.
In embodiments of the present invention, the IP head assembling the Snmptrap message of analogue network element specifically comprises: with the IP address of analogue network element in described analogue network element information list for source address, assemble the source IP address in described IP head; Address for the purpose of the IP address of described network under test management system, assembles the object IP address in described IP head; Assembling the type field in described IP head, being fixed as being 17, wherein 17 represent that transport layer protocol is udp protocol; Assemble the protocol version in described IP head and other fields; Calculate the School Affairs in described IP head, and assemble this field.
In embodiments of the present invention, the UDP head of the Snmptrap message of assembling analogue network element specifically comprises: the port assembling described UDP head, and be fixed as X, wherein X is greater than 1024; Assemble the destination interface of described UDP head, being fixed is 162, and wherein 162 represent Snmptrap port; Length field in assembling UDP head; Calculate the School Affairs in described UDP head, and assemble this field.
The Snmptrap message body assembling analogue network element in embodiments of the present invention specifically comprises: according to version number and the community assembling SNMP heading of the snmp protocol got; The Trap head of assembling SNMP message; According to the Snmptrap Variable-Bindings pair of the Snmptrap Variable-Bindings obtained to assembling Snmptrap message body.
In S104, send function by rawsocket and described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
In embodiments of the present invention, the socketid sending rawsocket will first be obtained; Then the cycle of Snmptrap message is sent according to the described analogue network element of user's input, use described socketid that described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
The method of the trap message of the multiple network element of the simulation that the embodiment of the present invention provides is owing to adopting rawsocket programming technique according to the configuration parameter of network under test management system and the Snmptrap message oneself assembling described analogue network element in advance according to the MAC Address of the analogue network element of pre-defined rule generation and IP address, thus user can be made to revise MAC Address in Snmptrap message and IP address, therefore, can realize really simulating multiple network element and send Snmptrap message to network under test management system, can be quick, networking test is carried out easily with network under test management system, the reliability and stability of effective inspection network under test management system.
Fig. 4 shows the structured flowchart of the system of the trap message of the multiple network element of simulation that the embodiment of the present invention provides, and this system is for running the method for the trap message of above-mentioned Fig. 1 ~ multiple network element of the simulation provided embodiment illustrated in fig. 3.Illustrate only the part relevant to the embodiment of the present invention for convenience of explanation.
Shown in Figure 4, the system of the trap message of the multiple network element of the simulation that the embodiment of the present invention provides, comprising:
Initialization module 1, for reading the configuration file of network under test management system, to obtain the configuration parameter of described network under test management system;
Act on behalf of generation module 2, for receiving and preserving the command parameter that user inputted by pseudo-terminal, read MAC Address and the IP address of described pseudo-terminal simultaneously, and generate MAC Address and the IP address of analogue network element according to the MAC Address of described command parameter and described pseudo-terminal and IP address according to pre-defined rule;
Depacketize module 3, assembles the Snmptrap message of described analogue network element for adopting rawsocket programming technique according to the configuration parameter of described network under test management system and the MAC Address of described analogue network element and IP address;
Message sending module 4, being sent to described network under test management system for sending function by rawsocket by described Snmptrap message, carrying out performance test to make described network under test management system according to described Snmptrap message.
Optionally, described initialization module 1 specifically for:
Read the configuration file of described network under test management system, to obtain and to preserve the version number of the snmp protocol that the MAC Address of described network under test management system, IP address and described network under test management system adopt, community and Snmptrap Variable-Bindings pair.
Optionally, described generation module 2 of acting on behalf of specifically comprises:
User input unit 21, for the number of analogue network element needed for the input prompt information input user of described pseudo-terminal and the cycle of analogue network element transmission Snmptrap message, reads MAC Address and the IP address of described pseudo-terminal simultaneously;
Analogue network element MAC Address generation unit 22, for with the number of analogue network element needed for user in described command parameter for the upper limit, with the MAC Address of described pseudo-terminal for plot, the cumulative MAC Address obtaining analogue network element, and the MAC Address of described analogue network element is saved in analogue network element information list;
Analogue network element IP scalar/vector 23, for with the number of analogue network element needed for user in described command parameter for the upper limit, with the IP address of described pseudo-terminal for plot, the cumulative IP address obtaining analogue network element, and the IP address of described analogue network element is saved in described analogue network element information list.
Optionally, described depacketize module 3 specifically comprises:
Rawsocket unit 31, for creating rawsocket, and arranges the option of socket in rawsocket, the IP packet header of the data that will send to make rawsocket manual handle;
Module units 32, for assembling the ETH head of the Snmptrap message of described analogue network element, IP head, UDP head and SNMP message body according to the MAC Address of analogue network element in the MAC Address of described network under test management system and IP address and described analogue network element information list and IP address.
Optionally, described message sending module 4 specifically comprises:
Socketid acquiring unit 41, for obtaining the socketid sending rawsocket;
Transmitting element 42, described analogue network element for inputting according to user sends the cycle of Snmptrap message, use described socketid that described Snmptrap message is sent to described network under test management system, carry out performance test to make described network under test management system according to described Snmptrap message.
It should be noted that, modules in said system, due to the inventive method embodiment based on same design, its technique effect brought is identical with the inventive method embodiment, particular content can see in the inventive method embodiment describe, repeat no more herein.
The system of the trap message of the multiple network element of the simulation that the embodiment of the present invention provides, equally owing to adopting rawsocket programming technique according to the configuration parameter of network under test management system and the Snmptrap message oneself assembling described analogue network element in advance according to the MAC Address of the analogue network element of pre-defined rule generation and IP address, thus user can be made to revise MAC Address in Snmptrap message and IP address, therefore, can realize really simulating multiple network element and send Snmptrap message to network under test management system, can be quick, networking test is carried out easily with network under test management system, the reliability and stability of effective inspection network under test management system.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, all any amendments done within the spirit and principles in the present invention, equivalent replacement and improvement etc., all should be included within protection scope of the present invention.