A kind of method and system of the trap message of the multiple network elements of simulation
Technical field
The invention belongs to the method for field of communication technology more particularly to a kind of trap message of the multiple network elements of simulation and it is
System.
Background technology
SNMP (Simple Network Management Protocol, Simple Network Management Protocol) is proposed earliest
One of Network Management Protocol, due to its simplicity, it is widely used and supports once releasing.Currently, SNMP has become
For the working stamndard in field of network management, most of Network Management System and platform are all based on snmp protocol to realize.
With the extensive use of snmp protocol, then NSM (Network Management System, a network management
System) management network element it is thousands of or even hundreds thousand of, then in existing net application environment, these network element at any times
Warning information is generated, and NMS is sent to by Trap message, at this moment NMS must have while handle hundreds thousand of reported by network elements
The ability of Trap message, therefore, in order to ensure being smoothed out for network management, when NMS comes into operation again, it is necessary to its performance into
Row test.Agent (agency) on NMS and managed element carries out the joint debugging stage, it tends to be difficult to dispose a large-scale survey
The problems such as test ring border, in addition to fund, place the problems such as, are intricate there is also the connection relation of real network.Therefore, city at present
A set of analog simulation testing tool is developed to replace various network elements realizations pair in actual environment in the joint debugging stage on
The performance test of Network Management System.
But since snmp protocol belongs to application layer protocol, and according to TCP/IP (Transmission Control
Protocol/Internet Protocol, transmission control protocol/Internet Protocol) procotol stack mechanism, transport layer
And its mechanism below is provided by kernel, application layer is provided by consumer process, and the analog simulation tool operates in a PC
On (Personal Computer, personal computer) machine, therefore the IP of network layer heads are the TCP/IP network protocol stack groups by kernel
Dress, transmitted Snmp trap are (when the trap message that managed devices report, i.e. managed devices break down or change
Proactive notification) IP address in message is all identical, although then the analog simulation tool can send Snmp with analogue network element
Trap message, but can only also simulate a network element and send Snmp trap message, and multiple network elements cannot be simulated simultaneously to network pipe
Reason system sends Snmp trap message.Therefore, current analog simulation tool has significant limitation, can not simulate true
Test environment.For this problem, traditional solution is to utilize the Variable-Bindings pair in Snmp trap message formats, definition
Privately owned definition message format, as provided second Variable-Bindings in Snmp trap messages to the IP address of expression network element, NMS
After collecting this message, second Variable-Bindings pair is parsed, the IP address of network element is obtained, according still further to process flow processing.The method
Also there is the Snmp trap message of certain limitation, essence or a network element, can not really receive the multiple network elements of complete simulation
Send out the flow of snmp message.
To sum up, multiple network elements can not really be simulated by still having in the prior art lacks to what Network Management System was tested
It falls into.
Invention content
The embodiment of the present invention is designed to provide a kind of method and system of the trap message of the multiple network elements of simulation, it is intended to
It solves the problems, such as existing in the prior art can not really simulate multiple network elements and test Network Management System.
The embodiment of the present invention is achieved in that a kind of method of the trap message of the multiple network elements of simulation, including:
The configuration file for reading network under test management system, to obtain the configuration parameter that the network under test manages system;
The command parameter that user is inputted by pseudo-terminal is received and preserves, while with reading the MAC of the pseudo-terminal
Location and IP address, and generated according to pre-defined rule according to the MAC Address and IP address of the command parameter and the pseudo-terminal
The MAC Address and IP address of analogue network element;
The configuration parameter of system and the simulation net are managed according to the network under test using raw socket programming techniques
The MAC Address and IP address of member assemble the Snmp trap messages of the analogue network element;
Function is sent by raw socket, and the Snmp trap messages are sent to the network under test management system,
So that the network under test management system is tested for the property according to the Snmp trap messages.
In the method for the trap message of the multiple network elements of simulation described in the embodiment of the present invention, the reading network under test pipe
The configuration file of reason system, the configuration parameter to obtain and preserve the network under test management system specifically include:
The configuration file for reading the network under test management system manages system to obtain and preserve the network under test
Version number, community and the Snmp of snmp protocol used by MAC Address, IP address and the network under test management system
Trap Variable-Bindings pair.
It is described to read the simulation eventually in the method for the trap message of the multiple network elements of simulation described in the embodiment of the present invention
The MAC Address and IP address at end, and according to the MAC Address and IP address of the command parameter and the pseudo-terminal according to predetermined
Rule generates the MAC Address of analogue network element and IP address specifically includes:
The number and analogue network element of analogue network element needed for user are inputted according to the input prompt message of the pseudo-terminal
The period of Snmp trap messages is sent, while reading the MAC Address and IP address of the pseudo-terminal;
Using the number of analogue network element needed for user in the command parameter as the upper limit, with the MAC Address of the pseudo-terminal
For plot, adds up and obtain the MAC Address of analogue network element, and the MAC Address of the analogue network element is saved in analogue network element information
In list;
Using the number of analogue network element needed for user in the command parameter as the upper limit, the IP address with the pseudo-terminal is
Plot adds up and obtains the IP address of analogue network element, and the IP address of the analogue network element is saved in the analogue network element information
In list.
It is described using raw socket in the method for the trap message of the multiple network elements of simulation described in the embodiment of the present invention
Programming technique manages the configuration parameter of system according to the network under test and the MAC Address and IP address of the analogue network element assemble
The Snmp trap messages of the analogue network element specifically include:
Raw socket are created, and the option of socket in raw socket is set, so that raw socket manual handles
The packet header IP for the data to be sent;
It is simulated according in the MAC Address of network under test management system and IP address and the analogue network element information list
The MAC Address and IP address of network element assemble the Snmp trap messages of the analogue network element ETH heads, IP, UDP and
SNMP message bodies.
It is described to pass through raw socket in the method for the trap message of the multiple network elements of simulation described in the embodiment of the present invention
It sends function and the Snmp trap messages is sent to the network under test management system, so that network under test management system
System is tested for the property according to the Snmp trap messages to be specifically included:
It the period that Snmp trap messages are sent according to the analogue network element input by user, will using the socket id
The Snmp trap messages are sent to the network under test management system, so that the network under test manages system according to
Snmp trap messages are tested for the property.
The another object of the embodiment of the present invention is to provide a kind of system of the trap message of the multiple network elements of simulation, including:
Initialization module manages the configuration file of system for reading network under test, to obtain the network under test management
The configuration parameter of system;
Generation module is acted on behalf of, the command parameter inputted by pseudo-terminal for receiving and preserving user, while reading institute
The MAC Address and IP address of pseudo-terminal are stated, and according to the MAC Address and IP address of the command parameter and the pseudo-terminal
The MAC Address and IP address of analogue network element are generated according to pre-defined rule;
Message assembles module, the configuration for managing system according to the network under test using raw socket programming techniques
The MAC Address and IP address of parameter and the analogue network element assemble the Snmp trap messages of the analogue network element;
Message sending module, for pass through raw socket send function the Snmp trap messages are sent to it is described
Network under test manages system, so that network under test management system is tested for the property according to the Snmp trap messages.
In the system of the trap message of the multiple network elements of simulation described in the embodiment of the present invention, the initialization module is specific
For:
The configuration file for reading the network under test management system manages system to obtain and preserve the network under test
Version number, community and the Snmp of snmp protocol used by MAC Address, IP address and the network under test management system
Trap Variable-Bindings pair.
It is described to act on behalf of generation module tool in the system of the trap message of the multiple network elements of simulation described in the embodiment of the present invention
Body includes:
User input unit, for inputting analogue network element needed for user according to the input prompt message of the pseudo-terminal
Number and analogue network element send the period of Snmp trap messages, while with reading MAC Address and the IP of the pseudo-terminal
Location;
Analogue network element MAC Address generation unit, for being with the number of analogue network element needed for user in the command parameter
The upper limit adds up using the MAC Address of the pseudo-terminal as plot and obtains the MAC Address of analogue network element, and by the analogue network element
MAC Address be saved in analogue network element information list;
Analogue network element IP address generation unit, for being with the number of analogue network element needed for user in the command parameter
Limit adds up using the IP address of the pseudo-terminal as plot and obtains the IP address of analogue network element, and by the IP of the analogue network element
Address is saved in the analogue network element information list.
In the system of the trap message of the multiple network elements of simulation described in the embodiment of the present invention, the message assembling module tool
Body includes:
For creating raw socket, and the option of socket in raw socket is arranged in raw socket units, so that
The packet header IP of the raw socket manual handles data to be sent;
Module units, the MAC Address and IP address for managing system according to the network under test and the analogue network element
The MAC Address of analogue network element and IP address assemble the ETH for the Snmp trap messages that the analogue network element is sent in information list
Head, IP, UDP and SNMP message bodies.
In the system of the trap message of the multiple network elements of simulation described in the embodiment of the present invention, the message sending module tool
Body includes:
Socket id acquiring units, for obtaining the socket id for sending raw socket;
Transmission unit in the period for sending Snmp trap messages according to the analogue network element input by user, uses institute
It states socket id and the Snmp trap messages is sent to the network under test management system, so that the network under test management
System is tested for the property according to the Snmp trap messages.
Implement the method and system of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention with beneficial below
Effect:
Configuration parameter of the embodiment of the present invention due to managing system according to network under test using raw socket programming techniques
The MAC Address and IP address oneself of the analogue network element generated in advance according to pre-defined rule assemble the Snmp of the analogue network element
Trap messages, so as to make user change MAC Address and IP address in Snmp trap messages, therefore, it is possible to realize really
Simulate multiple network elements to network under test management system send Snmp trap messages, can fast, easily with network under test management
System carries out networking test, the effective reliability and stability for examining network under test management system.
Description of the drawings
Fig. 1 is the specific implementation flow chart of the method for the trap message of the multiple network elements of simulation provided in an embodiment of the present invention;
Fig. 2 be the trap message of the multiple network elements of simulation provided in an embodiment of the present invention method in S102 specific implementation stream
Cheng Tu;
Fig. 3 be the trap message of the multiple network elements of simulation provided in an embodiment of the present invention method in S103 specific implementation stream
Cheng Tu;
Fig. 4 is the structure diagram of the system of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention.
Specific implementation mode
In order to make the purpose , technical scheme and advantage of the present invention be clearer, with reference to the accompanying drawings and embodiments, right
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.
Fig. 1 shows the specific implementation stream of the method for the trap message of the multiple network elements of simulation provided in an embodiment of the present invention
Journey.It is shown in Figure 1, the method for the trap message of the multiple network elements of simulation provided in an embodiment of the present invention, including:
In S101, the configuration file of network under test management system is read, system is managed to obtain the network under test
Configure parameter.
In embodiments of the present invention, know that the network under test manages the configuration parameter of system by user first, it is described to match
It includes MAC (Media Access Control, media access control) address, IP address and the network under test pipe to set parameter
The version number, community of snmp protocol used by reason system and Snmp trap Variable-Bindings pair, then by the configuration parameter
It is written in the configuration file of the network under test management system and preserves;The network under test pipe is finally read by pseudo-terminal
The configuration file of reason system manages the MAC Address of system, IP address and described to be measured to obtain and preserve the network under test
Version number, community and the Snmp trap Variable-Bindings pair of snmp protocol used by Network Management System.
In S102, the command parameter that user is inputted by pseudo-terminal is received and preserved, while reading the simulation eventually
The MAC Address and IP address at end, and according to the MAC Address and IP address of the command parameter and the pseudo-terminal according to predetermined
Rule generates the MAC Address and IP address of analogue network element.
Shown in Figure 2 Fig. 2 shows the specific implementation flow of S102, S102 is specifically included:
In S201, according to the input prompt message of the pseudo-terminal input user needed for analogue network element number and
Analogue network element sends the period of Snmp trap messages, while reading the MAC Address and IP address of the pseudo-terminal;
In S202, using the number of analogue network element needed for user in the command parameter as the upper limit, with the pseudo-terminal
MAC Address be plot, add up and obtain the MAC Address of analogue network element, and the MAC Address of the analogue network element is saved in simulation
In net element information list;
In S203, using the number of analogue network element needed for user in the command parameter as the upper limit, with the pseudo-terminal
IP address be plot, add up and obtain the IP address of analogue network element, and the IP address of the analogue network element is saved in the mould
In quasi- net element information list.
In embodiments of the present invention, pseudo-terminal can be PC terminals, and user can prompt to believe according to the input of PC terminals
Breath sends the period of Snmp trap messages by the number and analogue network element of the keyboard input simulation network element of PC terminals, if user
The period that the analogue network element of input sends Snmp trap messages is 0, then it represents that the analogue network element can be recycled uninterruptedly to waiting for survey grid
Network manages system and sends Snmp trap messages.
In S103, configuration parameter and the institute of system are managed according to the network under test using raw socket programming techniques
State the Snmp trap that the MAC Address of analogue network element and IP address described in analogue network element information list assemble the analogue network element
Message.
Fig. 3 shows the specific implementation flow of S103, and shown in Figure 3, S103 is specifically included:
In S301, create raw socket, and the option of socket in raw socket is set, so that raw socket
The packet header IP of the manual handle data to be sent.
In embodiments of the present invention, socket function creation raw socket are directly used, setsockopt is then used
The option of socket is set, the IP_HDRINCL in socket options is set as true, so that raw socket manual handles are wanted
The packet header IP of the data of transmission.
In S302, the MAC Address of system and the MAC of IP address and the analogue network element are managed according to the network under test
Address and IP address assemble the ETH heads of the Snmp trap messages of the analogue network element, IP, UDP and SNMP message bodies.
In embodiments of the present invention, the ETH heads for assembling the Snmp trap messages of analogue network element specifically include:With the mould
The MAC Address of analogue network element is source address in quasi- net element information list, assemble it is ETH described in source MAC;It is waited for described
Survey Network Management System MAC Address be purpose address, assemble it is ETH described in target MAC (Media Access Control) address;Assemble the ETH heads
In type field, be fixed as 0X0880, wherein 0X0880 indicates that network layer protocol is IP agreement.
In embodiments of the present invention, the IP heads for assembling the Snmp trap messages of analogue network element specifically include:With the simulation
In net element information list the IP address of analogue network element be source address, assemble it is IP described in source IP address;Survey grid is waited for described
Network manage system IP address be purpose address, assemble it is IP described in purpose IP address;Assemble it is IP described in type
Field is fixed to be 17, wherein 17 indicate that transport layer protocol is udp protocol;Assemble it is IP described in protocol version
With other fields;Calculate it is IP described in verification and, and assemble this field.
In embodiments of the present invention, the UDP heads for assembling the Snmp trap messages of analogue network element specifically include:Described in assembling
UDP ports are fixed and are more than 1024 for X, wherein X;UDP of the destination interface is assembled, it is 162 to be fixed,
Wherein 162 indicate the ports Snmp trap;Length field in assembling UDP;Calculate it is UDP described in verification and, and assemble
This field.
The Snmp trap message bodies of assembling analogue network element specifically include in embodiments of the present invention:According to what is got
The version number of snmp protocol and community assemble SNMP headings;Assemble the Trap heads of SNMP messages;According to the Snmp of acquisition
Snmp trap Variable-Bindings pair of the trap Variable-Bindings to assembling Snmp trap message bodies.
In S104, function is sent by raw socket, the Snmp trap messages are sent to the network under test
Management system, so that network under test management system is tested for the property according to the Snmp trap messages.
In embodiments of the present invention, it first has to obtain the socket id for sending raw socket;Then it is inputted according to user
The analogue network element send Snmp trap messages period, the Snmp trap messages are sent out using the socket id
It send to the network under test and manages system, so that the network under test manages system according to the Snmp trap message progressive
It can test.
The method of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention using raw socket due to being programmed
Technology according to network under test manage system configuration parameter and in advance according to pre-defined rule generation analogue network element MAC Address and
IP address oneself assembles the Snmp trap messages of the analogue network element, so as to make user change in Snmp trap messages
MAC Address and IP address, therefore, it is possible to realize that really simulate multiple network elements sends Snmp trap to network under test management system
Message fast, easily can carry out networking test with network under test management system, effective that network under test is examined to manage system
Reliability and stability.
Fig. 4 shows the structure diagram of the system of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention, should
The method that system is used to run the trap message for the multiple network elements of simulation that above-mentioned Fig. 1~embodiment illustrated in fig. 3 provides.For the ease of
Illustrate to illustrate only and the relevant part of the embodiment of the present invention.
It is shown in Figure 4, the system of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention, including:
Initialization module 1 manages the configuration file of system for reading network under test, to obtain the network under test management
The configuration parameter of system;
Generation module 2 is acted on behalf of, the command parameter inputted by pseudo-terminal for receiving and preserving user, while reading institute
The MAC Address and IP address of pseudo-terminal are stated, and according to the MAC Address and IP address of the command parameter and the pseudo-terminal
The MAC Address and IP address of analogue network element are generated according to pre-defined rule;
Message assembles module 3, for managing matching for system according to the network under test using raw socket programming techniques
It sets the MAC Address of parameter and the analogue network element and IP address assembles the Snmp trap messages of the analogue network element;
Message sending module 4, for pass through raw socket send function the Snmp trap messages are sent to it is described
Network under test manages system, so that network under test management system is tested for the property according to the Snmp trap messages.
Optionally, the initialization module 1 is specifically used for:
The configuration file for reading the network under test management system manages system to obtain and preserve the network under test
Version number, community and the Snmp of snmp protocol used by MAC Address, IP address and the network under test management system
Trap Variable-Bindings pair.
Optionally, the generation module 2 of acting on behalf of specifically includes:
User input unit 21, for inputting analogue network element needed for user according to the input prompt message of the pseudo-terminal
Number and analogue network element send periods of Snmp trap messages, while with reading MAC Address and the IP of the pseudo-terminal
Location;
Analogue network element MAC Address generation unit 22, for the number of analogue network element needed for user in the command parameter
It for the upper limit, using the MAC Address of the pseudo-terminal as plot, adds up and obtains the MAC Address of analogue network element, and by the simulation net
The MAC Address of member is saved in analogue network element information list;
Analogue network element IP address generation unit 23, for being with the number of analogue network element needed for user in the command parameter
The upper limit adds up using the IP address of the pseudo-terminal as plot and obtains the IP address of analogue network element, and by the analogue network element
IP address is saved in the analogue network element information list.
Optionally, the message assembling module 3 specifically includes:
For creating raw socket, and the option of socket in raw socket is arranged in raw socket units 31, with
Make the packet header IP of the raw socket manual handles data to be sent;
Module units 32, the MAC Address and IP address for managing system according to the network under test and the simulation net
In metamessage list the MAC Address of analogue network element and IP address assemble the Snmp trap messages of the analogue network element ETH heads,
IP, UDP and SNMP message bodies.
Optionally, the message sending module 4 specifically includes:
Socket id acquiring units 41, for obtaining the socket id for sending raw socket;
Transmission unit 42 in the period for sending Snmp trap messages according to the analogue network element input by user, uses
The Snmp trap messages are sent to the network under test and manage system by the socket id, so that the network under test pipe
Reason system is tested for the property according to the Snmp trap messages.
It should be noted that modules in above system, due to being based on same design with the method for the present invention embodiment,
The technique effect brought is identical as the method for the present invention embodiment, and particular content can be found in the narration in the method for the present invention embodiment,
Details are not described herein again.
The system of the trap message of the multiple network elements of simulation provided in an embodiment of the present invention, also due to using raw socket
Programming technique is according to the configuration parameter of network under test management system and the MAC of the analogue network element generated in advance according to pre-defined rule
Location and IP address oneself assemble the Snmp trap messages of the analogue network element, so as to make user change Snmp trap messages
In MAC Address and IP address, therefore, it is possible to realize really simulate multiple network elements to network under test management system send Snmp
Trap messages fast, easily can carry out networking test with network under test management system, effective to examine network under test management
The reliability and stability of system.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all essences in the present invention
All any modification, equivalent and improvement etc., should all be included in the protection scope of the present invention made by within refreshing and principle.