ns2 wireless LAN transmission simulation–hidden node

1. Introduction to related content:

“Hidden terminal” and “exposed terminal” are classic problems in wireless network conflict avoidance. This experiment uses the NS2 network simulator to test and analyze the hidden node problem.

Hidden node problem

1. Hidden nodes

Hidden nodes refer to nodes that are within the coverage of the receiving node but outside the coverage of the sending node. Since the data transmission of the sending node cannot be monitored, the hidden node sends packets to the same receiving node without restriction, causing packet conflicts at the receiving node. Hidden nodes can be divided into hidden sending nodes and hidden receiving nodes.

Nodes A and C want to send data to intermediate node B at the same time, but neither A nor C are within the transmission range of each other. So when A sends data to B, C does not detect that A is transmitting data, and will think that there is no data transmission in the current network, and will transmit the data to B. That is, A and C transmit data to B at the same time, causing data conflicts at B, resulting in data unavailability. This problem of misjudgment due to transmission distance is called the hidden node problem.

2. Solution

Use the “Request to Send” (RTS) and “Clear to Send” (CTS) mechanisms for channel reservation to reduce conflicts.

① Before sending data, the sender first sends an RTS packet to inform the nodes along the packet path (and the nodes within the transmission range) of the length of time that the entire communication process will occupy the channel.

② If the receiver is idle, it responds with a CTS packet to inform the packet path node (and the nodes within the transmission range) of the length of time that the channel will be occupied. Under the virtual carrier sensing mechanism, these nodes that receive RTS and/or CTS packets will learn the channel busy status and adjust their operations to reduce the probability of collision in the entire network.

③The sender sends the data packet.

④The receiver sends an ACK packet.

2. Experimental steps

Interpret the simulation code (Hidden_Terminal.tcl) and describe the simulation settings

The installation process of the modules required for simulation is as follows:

1. Obtain the module files of mUDP and mUdpSink. The following files are available in Baidu Netdisk. The main files are as follows: mudp.cc mudp.h mudpsink.cc mudpsink.h

Download address: https://pan.baidu.com/s/1-TE8xrwABEUfmDwc8gRozw
Extraction code: 7777

2. Create a new measure folder under /ns-allinone-2.35/ns-2.35/ and put these four files into it:

3. Modify the packet.h file under /ns-allinone-2.35/ns-2.35/common/ and add the following program to struct hdr_cmn{}

int frametype_;
double sendtime_;
unsigned int pkt_id_;
unsigned int frame_pkt_id_;
In vim command mode, enter /struct hdr and press Enter to find the location as shown in the picture faster

4. Modify the Makefile file under /ns-allinone-2.35/ns-2.35/ and add the following program to the specified location of the file

Note that Makefile has very strict syntax requirements and cannot have blank lines or extra spaces

measure/mudp.o measure/mudpsink.o \
In vim command mode, enter /pbc.o and press Enter to find the location as shown in the picture faster

Note: You may not be able to save due to insufficient permissions. Use the following command to change the permissions

sudo chattr -i Makefile
sudo chmod 777 Makefile

Then perform the above steps

Otherwise, the following error will be reported when proceeding to step 7:

5. Modify ns-default.tcl under /ns-allinone-2.35/ns-2.35/tcl/lib/ and add the following program to the last line of the file

Agent/mUDP set packetSize_ 1000
In vim command mode, enter G to find the location as shown in the picture faster

6. Modify the mudp.cc source code, otherwise the compilation will not pass.

The modified code is as follows:

mUdpAgent::mUdpAgent() : UdpAgent(), id_(0), openfile(0)
{
bind("packetSize_", & amp;size_);
//UdpAgent::UdpAgent();
}

7. Execute the following command in the /ns-allinone-2.35/ns-2.35 directory and the execution is completed.

sudo make clean
sudo make

3. Simulation process

Create a new folder dedicated to this experiment in /ns-allinone-2.35/ns-2.35, put the ns2 script Hidden_Terminal.tcl in it, and execute it with the following command:

ns Hidden_Terminal.tcl

Summary of problems encountered in simulation:

Question 1:

Solution:

When a file does not have permissions, execute the following command to grant permissions to the file

sudo vim filename
sudo chmod 777 filename

Question 2:

After going through the above solutions, it was found that problem 2 occurred, a segfault was caused (a segfault occurs when a program accesses a memory address space that does not belong to itself, or stores data in a memory address that does not have write permission. runtime error)

The cause is: The error reported in question 1 said that the corresponding file cannot be opened because there is no permission. During the solution process, we used sudo vim file name to create a new empty corresponding file, and sudo chmod 777 file name to give it permission, but we The created file is an empty file. Among the originally generated corresponding files, the file itself may have content. The essential reason for this problem is that the folder where it is located does not have enough permissions to generate the corresponding file we need< /strong>, so we should use the following methods to solve

Solution:

Grant permissions to current folder

cd .. to the upper directory, ll found that the permissions of the tmp folder are:

cd ..
ll

So change permissions:

sudo chmod 777 tmp

Enter the tmp folder again after changing:

cd tmp
ns hidden_terminal.tcl

4. Operation results

After the command is executed, the following image will appear:

After debugging (an image during the simulation):

syntaxbug.com © 2021 All Rights Reserved.