OPNET Modeler Example - Create a Packet Switched Network


1. Introduction to routines

This routine will simulate a simple packet switching network, which includes four peripheral nodes and a central node. The peripheral nodes are used to generate services, and the central node transfers these services to the corresponding destination nodes (one of the peripheral nodes). The network topology is shown in the figure below.
insert image description here
The above topology contains two types of node models, namely peripheral nodes and central switching nodes. The purpose of this routine is to simulate that the service sent by a peripheral node can be routed to another destination peripheral node through the central switching node. From the perspective of the central switching node, it is assumed that packets come from four peripheral nodes in a random manner, and each packet contains a destination address. The destination address can use an integer to represent different destination peripheral nodes. After receiving the packet, the central node passes The resolution of the address finally selects a suitable sender to send the packet to the destination.
The physical communication mechanism of the network is shown in the figure below.
insert image description here
Each node contains at least one pair of point-to-point transceivers, and forms a transceiver group through a wired duplex link and another pair of point-to-point transceivers. Each such transceiver group can support two-way transmission of data. Four pairs of point-to-point transceivers are configured in the central switching node, so as to physically support interconnection with four peripheral nodes.
The node model of the central switching node in OPNET is shown in the figure below.
insert image description here
How does the central switching node implement addressing and packet switching? Each directed packet flow (referring to a certain process model, a certain packet flow enters the process or leaves the process, so it is called a directed packet flow) has a unique index number, and this index number is always related to a certain A receiver (corresponding to the incoming packet flow) or a certain transmitter (corresponding to the outgoing packet flow) is uniquely corresponding, and the receiver and the transmitter are uniquely corresponding to a certain peripheral node, so the flow index number can be directly used as Basis for exchanging packets. Of course, in order to enhance the robustness of the network, we can also establish a mapping table of a destination address and a flow index (which can be regarded as a physical address). For the sake of simplicity, this routine will use the former method to realize addressing and packet exchange.
The node model of peripheral nodes in OPNET is shown in the figure below.
insert image description here
As the business source of the network, the peripheral nodes generate packets, assign a destination address to each packet and transmit it through the point-to-point transmitter. Peripheral nodes also serve as service terminals of the network. Peripheral nodes receive packets and count their end-to-end delays.
One of the essences of OPNET Modeler is the idea of ​​hierarchical modeling. When constructing this network, the following hierarchical modeling steps will be adopted: define the packet format --> define the link model --> create the central switching node model -- —>Create a peripheral node model—>Build a network model—>Configure and simulate.


2. Create a new package format

Create a new package format, open the package format editor, and set the properties of the package domain as shown in the figure below.
insert image description here
set at creation property is set to unset, which ensures that the property will not be assigned a default value when generating the packet.
After the setting is complete, name the package format and save it, and close the current editor.


3. Create a new link model

Next, create a new link model, open the link model editor, and set the supported link types as shown in the figure below.
insert image description here
Select ptdup as the supported link type, indicating that the link only supports point-to-point duplex connections.
The setting of each attribute value is shown in the figure below. Uncheck Support all packet formats and Support unformatted packets. The packet format only supports the one created by yourself.
insert image description here
ecc model is the error correction mode, select ecc_zero_err here, that is, cancel the error correction function of the link; error model is the interference mode of the link, select error_zero_err here, that is, the link has no interference; prodel model is the propagation delay calculation mode, here Select dpt_prodel to calculate point-to-point propagation delay; txdel model is the transmission delay calculation mode, here select dpt_txdel to calculate point-to-point transmission delay.
Here we also need to declare the external function link_delay. For versions above OPNET9.0, if the external function is not declared, an error will occur because the function cannot be found when compiling dpt_prodel.
Find the external function link_delay under File->Declared External Files, and tick it in front of it, as shown in the figure below.
insert image description here
Click OK, then save the link model.


4. Create a central switching node model

As mentioned earlier, the central switching node includes four pairs of transmitters and receivers, and a central switching process, which is used to forward packets by address.
First create a node model, place and name each object as shown in the figure below.
insert image description here
Right-click on the hub process module and select Show Connection to view the connection between each packet flow and the hub.
Next, you need to define the model properties of the transceivers. Hold down the Shift key and click all the transceivers with the left mouse button in turn. Be careful not to select the packet streamline. After selection, click the right mouse button on one of the receiver or transmitter modules to edit its properties.
Set the data rate to 9600 according to the labels in the figure below (consistent with the setting of the previous link model), select the packet format that you created earlier, and click the OK button, as shown in the figure below.
insert image description here
After editing the properties of one of them, tick the Apply to selected objects, set all the 8 transceivers selected in this way, and click the OK button.
insert image description here
Next, define the interface properties of the node model, select Node Interfaces in the Interfaces menu, and set the node as a fixed node, as shown in the figure below.
insert image description here
Then save the central switching node model.


5. Create the process model of the central switching node

In the central node model, the processor module hub receives a packet from the receiver module and forwards it to the correct transmitter module according to the destination address. The hub module connects the receiver and the transmitter through the packet flow. An interrupt is generated when a packet arrives and is received by the hub module. Because this interrupt is the only expected interrupt in the entire node, the finite state machine of the hub module process model requires only two states: a non-mandatory idle state as a wait between events; a mandatory state to contain the code for processing packets .
Create a new process model, open the process editor, create the state and transition line according to the figure below, and edit the condition settings of the transition line, and set the executive attribute to route_pk().
insert image description here
The code to define the macro is as follows.

#define PK_ARRVL (op_intrpt_type () == OPC_INTRPT_STRM)

The PK_ARRVL condition judges whether the interrupt type received by the hub process is the middle end of the stream. In OPNET, the constant OPC_INTRPT_STRM is used to represent the middle end of the stream. If the process receives other types of interrupts abnormally, the status will be wrong because the transition condition cannot be found, so it is The idle state creates a default transition line pointing to itself, that is, the condition is met if other conditions are not met.
Click the function block button on the toolbar, type the following code in it and save it.

static void route_pk(void)
	{
    
    
	int dest_address;
	Packet* pkptr;
	FIN(route_pk());  //函数开始
	pkptr = op_pk_get (op_intrpt_strm ()); //从合适的输入流中取得包
	op_pk_nfd_get (pkptr, "dest_address", &dest_address); //析取包中的目的域,目的地址就是输出流索引,将目的地址的值保留在本地变量中
	op_pk_send (pkptr, dest_address);  //根据目的地址将数据包发送给相应的收信机
	FOUT; //函数结束
	}

When writing a function, you must use FIN (function begin), FOUT (function out), FRET (function return) and other identifiers that define the scope of the function, and you must pair them.
Next, change the process properties, select Process Interfaces in the Interfaces menu, and set the property values ​​​​as shown in the figure below.
insert image description here
Click OK, save the process model and then compile the process, the compilation is successful as shown in the figure below.
insert image description here
Next, you need to assign the process module to the central switching node model, right-click on the hub process in the node model to edit properties, and assign the process model created above to the hub process, as shown in the figure below.
insert image description here
Save the node model after the above work is completed.


6. Create a peripheral node model

When a peripheral node generates a packet, it must specify a destination address for the packet, and then send it to the central node. If a neighboring node receives a packet, it must calculate the end-to-end delay of the packet. Therefore, the peripheral nodes must include a business generation module, a process module, a pair of point-to-point transmitter modules and a pair of point-to-point receiver modules to complete these tasks.
The perimeter node model places and names each object as shown in the figure below.
insert image description here
The property settings of the src module are shown in the figure below.
insert image description here
Next, the channel rate and supported packet formats of the transceiver need to be changed to match the specified link model.
Hold down the Shift key, click the receiver and transmitter in the peripheral node model, and edit their properties. The process is similar to that of the central node model, as shown in the figure below.
insert image description here
Select Node Interfaces in the Interfaces menu, set the node as a fixed node, and set it as shown in the figure below.
insert image description here
Some attributes can also be renamed. Attribute renaming can simplify complex attribute names, or expand oversimplified names. In short, it can help us better understand the role or function of the attribute.
The process of attribute renaming is shown in the figure below.
insert image description here
In addition, we can also assign a series of predetermined values ​​to a certain attribute, so that the setting of the attribute can be selected through the interface, which will provide convenience for users.
Specifying a predetermined value for an attribute has the following advantages: limit the range of attribute values; users can intuitively select the corresponding parameter according to the name of the predetermined value; users do not need to enter a specific value, just select from the drop-down list.
Next, specify some predetermined values ​​for the source interarrival time attribute just renamed, change all the Status of Symbol to suppress, and add four predetermined values, as shown in the figure below.
insert image description here
Many properties of surrounding nodes are irrelevant to simulation, and other properties are hidden here, as shown in the figure below.
insert image description here
Save the peripheral node model after the setting is completed.


7. Create a peripheral node process module

The functions of the peripheral node process module are: to assign a destination address for the packet and send it out; to calculate the end-to-end delay of the packet.
Create a new process model, open the process editor, create state and transition lines according to the figure below, and edit the condition settings of the transition lines.
insert image description here
In the init state, the process model will be loaded with a uniform distribution probability function from 0-3.
The xmt() transfer execution function generation will call the probability function to generate the destination address immediately, and assign it to the packet from the traffic generation module, and then send it out. The function of the rcv() transfer execution function is to calculate the end-to-end delay of the packet when it is received, and write the result to the global statistics.
In this process model, the code to define the macro is as follows.

/* 定义包流 */
#define RCV_IN_STRM 0
#define SRC_IN_STRM 1
#define XMT_OUT_STRM 0
/* 条件宏定义 */
#define SRC_ARRVL (op_intrpt_type () == OPC_INTRPT_STRM && op_intrpt_strm () == SRC_IN_STRM)
#define RCV_ARRVL (op_intrpt_type () == OPC_INTRPT_STRM && op_intrpt_strm () == RCV_IN_STRM)

RCV_IN_STRM and SRC_IN_STRM correspond to the input stream index number of the data packet, and XMT_OUT_STRM is the output stream index number. The input and output are relative to the current process module (proc), and they correspond to a packet stream connected to the proc module. Once the connection relationship is OK, their index numbers are constants.
Click the SV button on the toolbar to define the state variable, and enter the following content in the dialog box.
insert image description here
The following creates a global statistics probe to collect the results of the end-to-end delay of the packet.
Declare a global statistic as shown in the figure below under Interfaces->Global Statistics in the process module.
insert image description here
The entry execution code of the init state is as follows.

address_dist = op_dist_load ("uniform_int", 0, 3);
ete_gsh = op_stat_reg ("ETE Delay", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);

Click the FB button on the toolbar to open the function block editor, and type the following code in it.

static void xmt (void)
	{
    
    
	Packet* pkptr;
	FIN (xmt());
	pkptr = op_pk_get (SRC_IN_STRM); //从包流的输入流索引号获取数据包
	op_pk_nfd_set_int32 (pkptr, "dest_address", (int)op_dist_outcome (address_dist)); 
	//通过调用均匀概率分布函数指针(address_dist,在上面的init状态下定义),产生一个随机值,并将该值设置为包的"dest_address"域
	op_pk_send (pkptr, XMT_OUT_STRM); //从包流的输出流索引号将包发送出去
	FOUT;
	}

static void rcv (void)
	{
    
    
	Packet* pkptr;
	double ete_delay;
	FIN (rcv());
	pkptr = op_pk_get (RCV_IN_STRM);  //获取包指针
	ete_delay = op_sim_time() - op_pk_creation_time_get (pkptr);  //当前仿真时间减去包的创建时间得到包的端对端延时
	op_stat_write (ete_gsh, ete_delay);  //将计算的延时写入矢量结果文件中
	op_pk_destroy (pkptr);  //销毁包
	FOUT;
	}

The xmt() transfer execution function is executed when the SRC_ARRVL condition is met (that is, the packet arrives at the proc module from the service generation module). This function must assign a destination address to the packet before sending it.
The rcv() transfer execution function is executed when the RCV_ARRVL condition is met (that is, the packet arrives at the proc module from the receiver). The main purpose is to calculate the end-to-end delay and write the global statistical probe.
Set the property values ​​of the process interface according to the figure below.
insert image description here
Save the process model, go back to the peripheral node model editor, right-click the proc module and specify the process module of the peripheral node just created, as shown in the figure below.
insert image description here


8. Create a network model

The package model, link model, central switching node model, central switching node process model, peripheral node model, and peripheral node process model have been built before, and the next step is to build the network model.
File——>New—>Project to create a new network model, first place a subnet model in the project editing window according to Topology—>Subnets—>Create Fixed Subnets… and name it, as shown in the figure below.
insert image description here
Double-click the subnet module to enter its interior, open the object panel, search for the central switch node module and peripheral node modules created earlier, and place the node modules in sequence according to the figure below.
insert image description here
Search for the previously created link model, and connect the peripheral nodes 0, 1, 2, and 3 to the central switching node hub in turn (connect in sequence), as shown in the figure below.
insert image description here
After the connection is completed, you need to verify whether the link is connected correctly. Click Topology——>Verify Links, or directly use the shortcut key Ctrl+L to bring up the link inspection window, select Verify links, and click OK to verify. If there is a fork on the line, It means that the link is unreachable and there is a problem with the connection, as shown in the figure below.
insert image description here
At this time, it is necessary to check which step is wrong in the process of doing it myself. I just did not assign the corresponding process model to the node model, so an error occurred when verifying the connectivity of the link.


Nine, collect statistics

Next, collect statistics, right-click in the blank space of the project window and select Choose Individual DES Statistics, and check the global statistics ETE Delay, as shown in the figure below.
insert image description here
Right-click on the link between node_0 and hub, select Choose Individual DES Statistics, and select the utilization rate of the uplink and downlink according to the check in the figure below.
insert image description here
Save the project file.


10. Configure and simulate

In this routine, the packet size and transceiver rate are constant, so it is expected that the end-to-end delay should also be constant. However, if the packet generation rate is fast enough, it will cause some packets to accumulate in the transmitter queue, and the end-to-end delay of the packet will increase at this time. If the packet generation rate is uncertain, it may cause business bursts, so the end-to-end delay will also be affected. In order to simulate these behaviors, you need to configure the source interarrival time simulation property, which will be assigned two values ​​below.
Configure the simulation under DES——>Configure/Run Discrete Event Simulation (Advanced) in the menu bar, and open the window to configure the simulation parameters as shown in the figure below.
insert image description here
Assign a value of 4 to the source interarrival time attribute. The value selection here is the four values ​​preset when creating the surrounding node model, namely 4, 8, 40, and 80.
insert image description here
Copy this simulation sequence and paste it under this window, and assign the source interarrival time attribute of the newly pasted simulation sequence to 40, and keep other parameters unchanged, as shown in the figure below.
insert image description here
Save the simulation sequence of these two configurations, then run the simulation, click the simulation button in the figure below, the following window will appear after the simulation is completed, indicating that there is no error in the simulation process.
insert image description here
Click the View Results button to view the results. First, use the time_average display mode to view the utilization rate of the uplink, as shown in the figure below.
insert image description here
The utilization of the downlink is shown in the figure below.
insert image description here
It can be seen that the link utilization rate is very low because the packet generation rate is too small.
Let's check the global statistic ETE Delay. The result of simulation sequence 1 is shown in the figure below.
insert image description here
The results of plotting simulation sequence 1 in a discrete fashion are as follows.
insert image description here
The results of simulation sequence 2 are as follows.
insert image description here
The results of plotting simulation sequence 2 in a discrete fashion are as follows.
insert image description here
By comparison, it is found that the delay of simulation sequence 2 is better than that of simulation sequence 1.


Summarize

The above is an example of OPNET Modeler - all the content of creating a packet switching network. I hope this article will be helpful for you to learn OPNET Modeler software!
Bibliography of this article: OPNET Network Simulation/Edited by Chen Min. - Beijing: Tsinghua University Press, 2004

Guess you like

Origin blog.csdn.net/weixin_42570192/article/details/129634900