OPNET Modeler routine - performance comparison of ALOHA and CSMA


overview

This routine uses Ethernet as an example to discuss the modeling method of bus-type network, model and analyze the MAC technology of the data link layer, and compare the network performance of ALOHA and CSMA. Ethernet is an important computer local area networking method. It adopts a bus-type network modeling method, and nodes send and receive information through the bus.
The ALOHA protocol is the most basic random multiple access technology, and the CSMA protocol adds the function of carrier sense to it. For the introduction of ALOHA protocol and CSMA protocol, please refer to the article: Computer Network - Data Link Layer Media Access Control .
The bus model is jointly constructed by the receiving and sending node objects and the bus object, and the bus object is further divided into two objects: bus (Bus) and bus connector (Tap). The sending node transmits the data packet to the bus connector through the bus transmitter, and then the bus connector sends the packet to the bus for data transmission and sharing in the bus. The receiver receives data packets from the bus through the connector, and then performs data processing in the receiving node. The logic of the bus transceiver is shown in the figure below.
insert image description here
Both CSMA and ALOHA protocols are implemented in the sending node. ALOHA does not listen to the channel during the sending process, so the sending node does not need to receive signals. CSMA, on the other hand, needs to listen to the channel and then send the signal, thus requiring both a transmitter and a receiver. The figure below is a comparison of ALOHA and CSMA sending node models.
insert image description here
The single-arrow solid line is the packet flow line. At the sending end, the data source is sent to the transmitter after data transmission processing, and at the receiving end, the packet received by the receiver is transmitted to the receiving module. The dotted line with a single arrow indicates the status line, which notifies the data sending module that the channel of the receiver is busy or idle, and realizes the channel monitoring function. The dotted line with double arrows is a logic line, which is associated with the receiver and the transmitter.
The data source module is responsible for randomly generating data packets, which can be realized through the simple_source process model. The data receiving process only needs to destroy the receiving package and release the memory, which can be realized through the sink process model.
Pure ALOHAThe working principle: as long as the station generates a frame, it will immediately send it to the channel. If it receives a response within the specified time, it means that the transmission is successful, otherwise it will be resent.
Retransmission strategy: Wait for a random period of time to retransmit. If there is another conflict, wait for another random period of time until the retransmission succeeds.
The relationship between channel throughput and channel flow in pure ALOHA: S = G e − 2 GS=Ge^{-2G}S=Ge2 G
can be inferred, when G=0.5,S max = 1 2 e ≈ 0.18 S_{max}=\frac{1}{2e}≈0.18Smax=2e _10.18
1- Adhere to the working principle of CSMA: before sending a message frame, the sending node must listen to whether the media is in an idle state. When the channel is busy or a conflict occurs, the station that wants to send the frame will continue to listen, and it can be used as soon as it is free Send, if a response is received, it means the sending is successful, otherwise resend.
Retransmission strategy: Continuously monitor and send as soon as there is free time until the retransmission succeeds.
1- Stick to the relationship between channel throughput and channel flow in CSMA:S = G ( 1 + G ) e − GG + e − GS=\frac{G(1+G)e^{-G}}{G+e ^{-G}}S=G + eGG ( 1 + G ) eG
It can be deduced that when G=1, S max = 0.5 S_{max}=0.5Smax=0.5


1. Create ALOHA protocol model

The process model of ALOHA sending processing module is shown in the figure below.
insert image description here
Added integer status variable max_packet_count.
Under Interface->Global Attributes of the process editor, set as shown in the figure below.
insert image description here
The code in the header block is as follows.

/*input stream from generator module.*/
#define IN_STRM 0
/*output stream from generator module.*/
#define OUT_STRM 0
/*condition macros*/
#define PKT_ARVL (op_intrpt_type()==OPC_INTRPT_STRM)
/*global variables*/
extern int subm_pkts;

The initialization entry execution code is as follows.

/*get the maximum packet count set at simulation run-time*/
op_ima_sim_attr_get_int32("max packet count",&max_packet_count);

The entry execution code of the tx_pkt state is as follows.

Packet* out_pkt;
out_pkt=op_pk_get(IN_STRM);
op_pk_send(out_pkt,OUT_STRM);
++subm_pkts;
/*发送数据包总量等于系统仿真最大的数据包值时,结束仿真*/
if(subm_pkts==max_packet_count)
	{
    
    
	op_sim_end("max packet count reached.","","","");
	}

The property settings of the process interface are shown in the figure below.
insert image description here
The ALOHA node model is shown in the figure below.
insert image description here
The attribute settings of the gen module are shown in the figure below.
insert image description here
Make sure that the src stream and dest stream of the two packet streams are both src stream[0] and dest stream[0].
The node interface settings are shown in the figure below.
insert image description here


2. Create a CSMA protocol model

Save the process model of the ALOHA sending processing module and rename it, and modify the state transition diagram as follows based on it.
insert image description here
Only a few lines are added to the code of the header block, as follows.

/*input stream from generator module.*/
#define IN_STRM 0
/*output stream from generator module.*/
#define OUT_STRM 0
/*condition macros*/
#define PKT_ARVL (op_intrpt_type()==OPC_INTRPT_STRM)
/*input statistics indices*/
#define CH_BUSY_STAT 0
/*condition macros*/
#define FREE (op_stat_local_read(CH_BUSY_STAT)==0.0)
#define PKTS_QUEUED (!op_strm_empty(IN_STRM))
#define CH_GOES_FREE (op_intrpt_type()==OPC_INTRPT_STAT)
/*global variables*/
extern int subm_pkts;

Other than that, the rest of the settings are consistent with the process model of the ALOHA sending processing module.
The CSMA node model is shown in the figure below.
insert image description here
The node model is also modified on the basis of the ALOHA node model. The process model of the sink module is assigned as sink, the orange connection line is optional, and the red status line attribute settings are shown in the figure below.
insert image description here


3. Create receiver process and node model

In this example, the receiver models used by ALOHA and CSMA are the same, so create them below.
The process model of the receiver is shown in the figure below.
insert image description here
Define an integer state variable rcvd_pkts, and add the following code in the initialization entry code.

rcvd_pkts=0;

The header block code is as follows.

#define IN_STRM 0
#define PKT_RCVD (op_intrpt_type()==OPC_INTRPT_STRM)
#define END_SIM (op_intrpt_type()==OPC_INTRPT_ENDSIM)
int subm_pkts=0;

The function block code is as follows.

/*this function gets the received packet,destroys it,and logs the incremented received packet total.*/
static void proc_pkt(void)
	{
    
    
	Packet* in_pkt;
	FIN(proc_pkt());
	/*get packet from bus receiver input stream*/
	in_pkt=op_pk_get(IN_STRM);
	/*destroy the received packet.*/
	op_pk_destroy(in_pkt);
	/*increnment the count of received packet*/
	++rcvd_pkts;
	FOUT;
	}

/*this function writes channel triffic and throughput statistics at the end of simulation.*/
static void record_stats(void)
	{
    
    
	double cur_time;
	FIN(record_stats());
	cur_time=op_sim_time();
	op_stat_scalar_write("Channel Traffic G",(double)subm_pkts/cur_time);
	op_stat_scalar_write("Channel Throughput S",(double)rcvd_pkts/cur_time);
	FOUT;
	}

The property settings of the process interface are shown in the figure below.
insert image description here
The node model of the receiver is shown in the figure below.
insert image description here
Assign a process model to the rx_proc module, and set the hidden attribute in the node interface to only support fixed nodes.


4. Create a bus link model

Create a new link model that only supports bus and bus interface, set it according to the figure below, and save the model.
insert image description here


5. Create a network model

Create a new project file, create an Office scene, and set the size to 700m × 700m.
In the object panel, add the previously created sending node, receiving node and link model to the panel of the current scene.
Select Topology——>Rapid Configuration in the menu bar, select Bus, and set various parameters as shown in the figure below.
insert image description here
Then select a tap, right-click to select Select Similar Links, then edit its properties, set its model to the previously created link model, check Apply to selected objects at the bottom, and click OK.
Find the receiving node model in the object panel, add it to the project, and select the bus connector in the link model you created to connect the bus and the node.
The completed ALOHA network model is shown in the figure below.
insert image description here
The value of the global attribute max packet count is set to 1000.
insert image description here
The object attribute Packet Interarrival Time is set as a multi-exponential random variable with mean values ​​of 20, 30, 40, ..., 170, 180.
insert image description here
The simulation time is set to 3 hours.
After the above settings are completed, copy the scene, remove the original ALOHA sending node in the copied scene, and add the CSMA sending node. Just select CSMA, then check the Apply to selected objects at the bottom, and click OK.
The completed CSMA network model is shown in the figure below.
insert image description here
Pay attention to adding a receiving function to the bus connector. Since CSMA needs to listen to the channel and then send a signal, it needs both a transmitter and a receiver. The arrows are bidirectional.


6. View the simulation results

The simulation parameters have been set up before, just run the simulation.
The results of the simulation using the ALOHA protocol are shown in the figure below.
insert image description here
The X-axis in the figure above is the channel traffic, the Y-axis is the throughput, and the simulated random seed number is 1280. It can be seen from the simulation results that when using the ALOHA protocol simulation, as the traffic increases, the throughput first increases and then decreases.
The results of the simulation using the CSMA protocol are shown in the figure below.
insert image description here
In the figure above, the X-axis is the channel traffic, the Y-axis is the throughput, and the simulated random seed number is 1500. It can be seen from the simulation results that when the CSMA protocol is used for simulation, as the traffic increases, the growth rate of the throughput decreases gradually, and then tends to be stable.
After clicking Show, you can set the two curves to be drawn together, as shown in the figure below.
insert image description here
You can also right-click to edit the graphic properties, and modify the title on the upper left.
From the simulation results in the above figure, it can be seen that the maximum throughput of the ALOHA protocol will not exceed 0.18, and the maximum throughput of the CSMA protocol will not exceed 0.5. In general comparison, the performance of CSMA is much better than that of ALOHA.
The number of random number seeds will also affect the direction of the throughput curve, you can try it yourself.


Summarize

The above is all the contents of the OPNET Modeler routine - ALOHA and CSMA performance comparison. I hope this article can let you understand the difference between ALOHA and CSMA!
Reference article: Simulation of Communication Network Based on OPNET / Gao Lin. ——Xi'an: Xidian University Press, 2018.2

Guess you like

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