Network protocol research tool

This article distributed under the Creative Commons agreement.

Research network protocol, network protocol emulation needs to be done, and then come into contact with ns3 and wireshark.
 Well, Closer to home, the following began to introduce the relevant knowledge of NS3.
1 ns3 Introduction
1.1 ns3 definition description
ns3 is a discrete event driven network simulator, mainly used in research and education, designed to meet the needs of the academic and teaching.

ns3 project is to develop a fully open source project, launched in 2006. The first version was released in June 2008, the latest version of the ns-3.15.

ns3 suitable platforms, including: Linux, Mac OS, Cygwin (imitation Linux environment under Windows).
Different 1.2ns3 and ns2 of
ns3 not extend ns2, but a new simulator.
ns2 using code written in C ++ and OTcl, in the learning process to learn a new language OTcl. The ns3 used in all written in C ++, and Python language bindings with an optional, user can select either C ++ or Python scripting language code to use more flexible.
ns3 does not support API NS-2's. Although ns2 Some modules have been ported to ns3 but ns3 ns2 far from perfect. In the process of development in ns3, ns3 project team will continue to maintain ns2, but also study the transition and integration mechanisms. ns3 does not contain all the features currently NS-2, but it has some new features, such as: the right multi-card processing, using IP addressing scheme, more detailed 802.11 module and so on.
1.3 NS-3 for more resources the way
a user can obtain more detailed information about ns3 from the following Web sites:
1. Main site located http://www.nsnam.org, provide basic information ns3 system.
2.http: //www.nsnam.org/ns-3-dev/documentation/ The main page includes the following information:
the Tutorial: Introduction preliminary knowledge of NS-3, as well as download and install, simple to use.
Manual: to explain the deeper knowledge ns3 and coding style of NS-3.
Model Library: Introduces ns3 related modules. Users can select modules to learn their actual needs, you do not need to look at all.
3.http: //www.nsnam.org/doxygen/index.html on this page provide more detailed information ns3 system architecture. When writing your own modules, a member of the class of query functions, properties, or any such thing, you should always use this link.
4. Wikipedia page http://www.nsnam.org/wiki can complement NS-3 primary sites.
5.ns3 source code can be found in http://code.nsnam.org. Readers can also find the current NS-3 development tree named ns3-dev source repository. And until then ns3 releases and the latest test version of the code.
2 download and install ns3
2.1 download package ns3
We Ubuntu Linux environment as an example, download and install ns3, and by running a simple script, to verify that the installation was successful.
New directory for storing downloaded NS3 package. Directory name can be self-created. As the new directory called ns3_install:

mkdir ns3_install

enter ns3_install directory, download the latest version of NS3 source code to the directory, and unzip it. To download ns-3.15 version of the source code as an example:

cd ns3_install

https://www.nsnam.org/release/ns-allinone-3.30.tar.bz2 wget

the tar-3.30.tar.bz2 XJF NS-allinone

directory named after decompression ns-allinone-3.30 /.
2.2 compiler package NS3
2.2.1 compiled using build.py

first compilation NS3 package, recommended ./build.py --enable-examples --enable-tests command to download the source code to compile overall.

First, switch to the directory above the de compression:

cd ns-allinone-3.30

, type the following command to compile the script began to compile, compile the first time with a longer, please be patient:

./build.py --enable-examples - enable-tests

when compiling script start compiling download ns3, you will see a number of common compiler input information. Finally, see compilation success message:

'Build' Finished successfully (40m30.586s)

compilation is completed, generate a directory called ns-3.30 / in the current (ns-allinone-3.30) directory, change directory under

CD-NS 3.30
2.2.2 compiled using waf
addition to the methods described above, we can compile the source code with NS3 waf. Before compiling with waf, first to understand waf.
After downloading the source code reader NS3, the need for source code to be compiled to produce an executable program. As the source code management a variety of ways, there are a variety of tools to compile the source code. The most commonly used tool is the make. Make shortcomings is that it may be to compile a large and highly configurable systems a way the hardest. Therefore, there are many alternative tools have been developed. Recently, large-scale highly configurable system compilation tools mostly choose to use Python language to develop.
NS3 build system uses Waf. It is a new generation of Python developers build management systems. Readers do not have to master the python, you can compile existing NS3 project. If readers want to extend existing NS3 system, in most cases you need to know a subset of the very few and very intuitive knowledge of Python.
More details about Waf, you can get by http://code.google.com/p/waf/.
Then enter the subject of this section, to configure and start using waf NS3 compile the package.
When using waf of NS3 source code is compiled, it can be divided into optimizing compiler to compile and debug both cases. The default debug compiled.
In order to inform waf optimized compiler, you need to execute the following command:

./waf Clean

./waf -d Optimized --enable-examples the configure --enable-Tests

To prevent duplicate compiler error may bring, the first command first empty contents previously compiled (compiled content located in the ns-3.30 / build / directory). This command is not required, but doing so is a good habit. After you type the second command, the system starts checking compiled various dependencies and compile it. You can see output similar to:

Checking for Program G ++: the ok / usr / bin / G ++

Checking for Program cpp: the ok / usr / bin / cpp

Ar Program for Checking: the ok / usr / bin / Ar

Checking for Program ranlib: the ok / usr / bin / ranlib

Checking for G ++: the ok

..................

'the configure' Finished successfully (2.870s)

last statement shows that the smooth compiled.

At compile time to note that some characteristics of ns-3 is not turned on by default, support the underlying system needs to be able to run smoothly. For example: To run xmlto, the system must be installed libxml-2.0 libraries, if the library is not found, the respective characteristic ns-3 will not be activated, which will be displayed in a message. Another point to note: for certain programs, you need to use the sudo command to set the program, and these programs may be set to off by default, so this property will be displayed inactive.

Similarly, we can also debug compiled (for the convenience of subsequent explanation, it is recommended to select compilation mode debug compile time):

./waf Clean

./waf -d Debug --enable-examples-Tests the configure --enable

addition by parameters - o, change the compiled object directory, the default directory is compiled build /. By the following command to change the destination directory is compiled Build / Debug /

./waf -o -d Debug Build / Debug --enable-examples the configure --enable-Tests

there are many other options available in the configuration and compilation of waf . More options can be viewed with the following command:

./waf --help
2.3 to test the correctness of compilation

After compilation is complete, you can test the correctness of ns-3 package by running "./test.py -c core" script,

./test.py -c Core

these tests can be performed in parallel waf, you can see the last results are as follows:

136 of 139 tests passed (136 passed, Skipped. 3, 0 failed, Crashed 0, 0 Valgrind errors)

during the test, the following information can be seen similarly:

Waf: Entering Directory '/ Home / ... ... / NS-allinone-3.15 / NS-3.15 / Build '

Waf: Leaving Directory' /home/....../ns-allinone-3.15/ns-3.15/build '

' Build 'Finished successfully (1.799s)

the PASS: NS3 the TestSuite Interference--WiFi

the PASS: the TestSuite IPv4-address-Helper

the PASS: the TestSuite Devices-WiFi

the PASS: the TestSuite-propagation-Loss Model

...

136 139 Tests of passed (136 passed, Skipped. 3, 0 failed, Crashed 0, 0 errors Valgrind )

users typically can run this command to check the correct bundles NS3 compiled.
2.4 Running a script
We usually use waf run the script. When properly compiled NS3 package, if you want to run a program, you can simply add --run option after waf. Let's run a common Hello Simulator program in ns-3 environment, the program is equivalent to the time of the Hello World program to learn a language:

./waf --run the Hello-Simulator

Waf will first check the program compile correctly, but also You may need to re-compile. Waf implementation of this program, and outputs the following information:

the Hello Simulator

If you do not see the output "Hello Simulator", describe the compiler you are carried out in the optimizing compiler mode, the compiler optimization mode, turned off by default console output. Through the following command:

./waf Clean

./waf -d Debug --enable-examples the configure --enable-Tests

recompile compiled in debug mode.

Until now, we successfully compiled NS3 download package, and to verify the correctness of the package and run Hello Simulator test scripts. If you want to run as gdb or valgrind under the program in other tools, see Wiki entry.
Quick Start 3 NS3
few key concepts of an NS3 3.1
3.1.1 Node node
in the network terminology, any computer connected to the computing devices of the network are called hosts, also known as a terminal. NS3 is a network simulator, rather than a dedicated Internet simulator, and we avoid the term "host" because the term is too easy to think of the Internet and its related protocols. Therefore, we chose from a graph theory, the term is also widely used in other network simulator: node.
NS3 basic computing device is abstracted as a node. Node described by the Node class written in C ++. Node class provides a method for managing a computing device.
Node can be conceived as a variety of functions can be added to the computer. In order for a computer to work effectively, we can add applications to it, protocol stacks, and other peripheral cards and drivers. NS3 using this same model.
3.1.2 channel
in the real world, people can connect your computer to the network. We usually media data flow through the network is called a channel. When you put the cable into the Ethernet jack on the wall, you are connected to the computer via an Ethernet channel. In NS3 may be connected to the node object representing data exchange channel. Here, the abstract concept of basic communication subnetwork is called a channel, a Channel type written in C ++ will be described.
Channel management class provides various methods and subnet object communication node is connected to the channel. Channel class may also be an object-oriented method of customized by the developer. A channel instance to simulate a simple cable (Wire), can also simulate a huge complex Ethernet switch, a wireless network and even three-dimensional space filled with an obstacle.
In this chapter we will use the example of several channel model, comprising: CsmaChannel, PointToPointChannel and WifiChannel. For example, CsmaChannel channel for a simulated channel may be implemented in the carrier sense multiple access, the Ethernet channel having similar functions.
3.1.3 network device
if you want a computer connected to the network, the card must be installed on the computer. If a network card software drivers to control the hardware is not a lack of work. In the Unix / Linux systems, peripheral hardware is classified as "Device." Devices controlled by the driver, and the card is controlled by the NIC driver. In the Unix / Linux systems, the card is called names like eth0.
In NS3, the network device corresponds to the abstract concept of hardware devices and software drivers combined. NS3 simulation environment, the network device corresponds installed on the node, such node and the other node communication channel. Like a real computer, as a node can be connected to a plurality of channels simultaneously by a plurality of network devices.
NetDevice network device is described by using the class in C ++. NetDevice class provides a method of managing other nodes and connecting channel of the object, and allows developers to customize the object-oriented approach. We use several instances of a particular network device in the present course, they are CsmaNetDevice, PointToPointNetDevice, and WifiNetDevice. As Ethernet card is designed to operate in the same Ethernet, CsmaNetDevice is designed to work in csma channel, while PointToPointNetDevice work in PointToPoint channel, WifiNetNevice work in wifi channel.
3.1.4 application
computer software can generally be divided into two categories: system software and application software. The calculation model system software configuration, and management of computer resources, such as memory, processor cycles, hard disk, network and the like. System software typically does not use these resources to complete user tasks. Users often need to run the application to complete certain tasks, while the application needs to use resources that are controlled by the system software.

In general, the boundaries of system software and application software for the privilege level of performance changes, and this change is through the operating system of self-trapping function (operating system traps) to achieve. In NS3 and no real concept of the operating system, and no concept of privilege levels or system calls. However, we have the concept of applications. As the "real world" applications running on the computer to perform various tasks, application NS3 simulation environment running on a node to drive the simulation.

In NS3, we need to be simulated user program is abstracted for the application. Application to describe a class. This class provides the method for managing the simulation of the user-level application. Developers should customize and create new applications using object-oriented approach. In this tutorial, we will use two instances of the Application class: UdpEchoClientApplication and UdpEchoServerApplication. These applications include a client application and a server application to send and respond to packets in the simulated network.

Guess you like

Origin www.cnblogs.com/evilqliang/p/12488889.html