Sunteți pe pagina 1din 17

The basic concept NSG2

To generate the script file using NSG2 very simple in design NSG2 users when it is
hoped that the most natural and most intuitive way to generate ns2 script file, so as far
as possible "WYSIWYG" approach to the design, that is Most users see on the screen
directly to the location of Node, as well as other relevant information (coordinates, users
can connect so ...), the script is generated, the demand for their own self to make
appropriate changes After the script file archive (. tcl) then referred to the
implementation of ns2 can, so use very simple, if you can grasp the key points, you can
easily operate NSG2.
The following will address the basic concepts of several NSG2 a simple description, in
NSG2, the most convenient place is to have wireless network in the Node coordinates
to the author's experience, writing the script file ns2 wireless network must provide The
coordinates of each Node (including x, y, z), is to produce large and regular Node, will
write the script file become very cumbersome, and this is the original author wanted to
write a tool to assist their users Causes the script file generated to NSG2 to generate
the coordinates of Node is a fairly easy task.
When using NSG2 mainly divided into five modes, which are mostly in accordance with
ns2 several objects to the main design, the relationship between the objects can refer to
Figure 3. To switch between each mode, just press the button to switch the top of the
screen, NSG2 contains the following five modes:

modes:
1. Hand mode
2. Node mode
3. Link mode(只適用於有線網路劇本)
4. Agent mode
5. Application mode

Application CBR, FTP ... Application

Agent TCP, UDP ... Agent

Node Link Node


Complex, Duplex
圖 3. NSG2

In Hand mode mode features the most simple, mainly to allow the user to adjust the
range to watch. When building a large script maycontain a large number of Node, the
screen may not fit all of theobjects, when the Hand mode can be used to adjust the
scope toview, use the mouse just hold the left button, then drag the Be

Node mode
In Node mode mode, the user can configure Node position, if it is wired network script,
then the coordinates of Node is not very important, mainly to set the relative position of
fills, but the NSG will set according to the relevant location of Node To configure the
position of the NAM in the Node.
When the script in the design of wireless networks, Node coordinates to become very
important because the coordinates of each Node will affect the transmission range,
signal strength and Routing protocol, etc. So when the script in the build wireless
networks, NSG2 will Bottom of the screen shows the coordinates of the information as a
reference. And the NSG would assume that the transmission of wireless network Node
distance 250m (the actual simulation of the effective transmission distance is set
according to the wireless network parameters to determine), so when the two Node
within the transmission distance of 250m when, NSG2 will Draw a connection between
the two, the user can click Node and drag the mouse to adjust the position to be placed
in the Node. In addition, under the Node mode also provides a way to generate multiple
Node, which includes: Chain vertical and horizontal, Grid (n × n) and Random, users
simply set the distance between Node and Node, Can easily produce large and regular
network topologies.

Link mode only applies to the wired network script does not need the wireless network
settings available in Link mode to set the link between Node and Node, such as
Simplex-link or Duplex-link, and set the relevant parameters (Transmission rate, the
type of queue, etc.). When you first set the property, and then use the mouse to select
the two Node to link to, set up, they could use the link right to modify or delete the link
parameters.

In Agent mode, the user can set on the Node to be attached to the protocol (in ns2
called the Agent), the main support current NSG2 TCP (including a variety of
deformation) and the UDP protocol, the set method is very simple, as long as you want
Additional Node click the left mouse button, and then click the location to be placed to
Agent, Agent attached which focuses on a Node and not its location, just to set the
location of the display screen fills location so the user can easily be placed in clearly
identifiable location.
In addition to setting in Agent mode belongs Node Agent, but also can set the
transmitter and receiver side information, select the two to use as long as the Agent can
be matched, in general, in the ns2 TCP Agent must correspond to the TCP- Sink Agent,
and the UDP Agent is mapped to the Null Agent, which TCP Agent and the UDP Agent
is the sender, and TCP-Sink Agent and Null Agent is a TCP Agent, respectively, and
UDP Agent of the receiver. In setting the transmitter and receiver pair should pay
attention to the problem, for example, pairing up two TCP Agent, or a TCP Agent and a
UDP Agent paired up is meaningless.
When setting the Agent, the right can also be used to modify the parameters to modify
or delete Agent Agent, some details of the parameters can not be directly produced
Agent settings, you must first establish a good Agent, and then use the right-click pop-
up menu to set, for example, TCP's congestion window and packet size, and other
related settings.
Application mode
In the Application mode model can be used to set the top under the application, such as
CBR with FTP, setting as long as the Agent to attach, click the left mouse button, and
then click Application to be placed in the position to the same The focus of the
Application Agent not attached in its position, so long as the clear position of the set
easily identifiable location.
Agent time and setting, as well as set the Application, you can use right to modify or
delete the parameters of Application Application, some of the parameters in the
production Application details can not be set directly, we must first establish a good
Application, re-use right The pop-up menu to set, for example, the Transmission rate
and the CBR packet size and other related settings.
Parameters
In addition to these five modes, in addition to the function parameter, the script in the
wired network, the parameter set contains the simulation time and Trace file name
(including the NAM's Trace files), but when the script in a wireless network , the other
more than a wireless network (Wireless) and channel characteristics (Channel) of the
relevant settings. Comparison is worth mentioning that the relevant characteristics of
the channel settings, NSG2 802.11b provides a set of analog reference value, but in
case of default is not enabled, if the user wants to enable these settings, then select the
picture box to the left, of course, the needs of the simulation can set a new value.
When everything is set finished, press the button to generate TCL TCL script file, the
user can own this time in the script file to make some adjustments, adjustments can
save the file after completion and use ns2 to do it.
Finally, there are several points to note:
1. When setting parameters, if the necessary parameters, the user must provide, or
NSG warning message will pop up; if non-essential parameters, you can enter -1, -1 if
the parameter is set to generate TCL script file so when the NSG This parameter is
ignored. In addition, NSG not to check the correctness of parameters, such as entering
a queue size of -50 then the NSG will be "honest," writes the value to which the script
file.
2. When the deleted object, the object belongs to one and is related objects will be
deleted, such as deleting a Node, then all connected to the Node's Link and all the
Agent attached to the Node will be deleted, and when the Agent is deleted , all attached
to the Application of the Agent and was also a deleted.
3. If the set Agent, do not set the sender (or receiver), then generate TCL script file
when the Agent will be ignored, because even if the Agent's configuration files were
added to the simulation scenario there will be no effect.
Wired network with the NSG to generate the script
Then I will introduce a simple example of how to create a wired network NSG in the
script file, the simulation environment shown in Figure 4.
cbr0 udp0 null2

n0 n4
2 Mbps, 10 ms 2 Mbps, 10 ms
1 Mbps, 20 ms
n2 n3

2 Mbps, 10 ms 2 Mbps, 10 ms
n1 n5

cbr1 udp1 null3

1. N0 and n4 is between a protocol UDP CBR connection (marked as cbr0).


2. N1 and n5 as between a protocol UDP CBR connection (marked as cbr1).
3. N0-n2, n1-n2, n3-n4, n3-n5 bandwidth of between 2Mbps, the delay time is set
to 10ms.
4. N2-n3 between the bandwidth is set to 1Mbps, delay time is set to 20ms.
5. all the links are all Duplex-link, queue management mechanisms are based on
the DropTail, and queue length (Queue limit) are set to 10 packets length.
Set in the application areas:
1. Cbr0 packet size is set to 1500bytes, and to the transmission speed of 1Mbps
to send data, the simulation start time of 1 seconds to send data, in the end of 4
seconds to send.
2. Cbr1 packet size is also set to 1500bytes, and to the transmission speed of
1Mbps to send data and the simulation time is 2 seconds starts sending data, in
the first 3 seconds when the end of the transfer.
3. the whole simulation time is set to 5 seconds.
Note: Due to the UDP protocol ns2 default packet size is 1000bytes, that is, the
time when the UDP packet size is larger than 1000bytes packet will be cut into
smaller pieces to send (Segmentation), so the setting needs an UDP packet size
is 1500bytes applications in order to avoid the top of the UDP packet is cut.
In this experiment, you can find two cbr connection will be through the n2-n3 this
link and this link with a bandwidth of 1Mbps, but cbr0 transmission speed of
1Mbps, it makes all the n2-n3 bandwidth Percentage of packets to be cbr0 full,
so when cbr1 began after the transfer, will find n2-n3 traffic congestion began to
change over time, the queue when n3 is filled, it will begin to have some packets
Discarded in n3, this phenomenon has continued to cbr1 after the end of
transmission.
Practice
Step1: Add the script of a wired network, users can Scenario → New wired
scenario to create (or by pressing Ctrl W), is established as shown in Figure 5, in
the case of default, will switch to the NSG Node mode (Node button becomes
gray), which means that users can start to establish Node.

2.

Step2: create the script needed start Node, use the mouse to click directly to the
location you want to display to create a Node Node, in this example to establish the
relative position of the six Node as shown in Figure 6, bottom right by adjusting the
screen Bar shows the proportion of different
Figure 6: setting the relative positions of six node
Step3: Set the link between Node, the first switch to the Link mode (press the Link
button or shortcut keys Ctrl +3), and then order the following parameters will be set up.
1. Link-type: duplex-link
2. Queue type: DropTail
3. Capacity: 2Mbps
4. Propagation delay: 10ms
5. Queue size: 10
Step4: Click the mouse manner n0-n2, n1-n2, n3-n4 and n3-n5 link between the
established, then the Capacity is set to 1Mbps, Propagation delay is set to 20ms, and
then create n2 -n3 between the links, as shown in Figure 7 after the establishment of a
good, if there are parameters to establish the process did not set up, you can also right
click on the link to be modified.
Listen
Read phonetically

Dictionary - View detailed dictionary


Figure 7: set up the link between the six node
Step5: Then switch to the Agent mode (press the Agent button or shortcut keys Ctrl +4)
to the protocol settings. First, select the Agent type to UDP and set the packet size
(Packet size) is 1500 bytes, and n0 and n1 with the establishment of an Agent, then
select the Agent type is NULL, and n4, n5, on the establishment of a NULL Agent. After
the establishment of a good Agent Agent will continue to set the connection between
the way its set to establish a connection with the mouse to select the two Agent,
respectively, in this (udp0, null2) and (udp1, null3) between Establish a connection,
shown in Figure 8 after being established.
Listen
Read phonetically

Dictionary - View detailed dictionary


Figure 8: Agents
Step6: Switch to the Application mode (press the Application button or shortcut keys Ctrl
+5) to the upper application settings, set the Application type CBR and set the start time
(Start time) 1 second, end time (Stop time) 4 seconds, the packet size is 1500bytes,
transmission speed of 1Mbps, then n0 on the establishment of a CBR Application, then
the start time (Start time) for 2 seconds, end time (Stop time) is 3 seconds, and further
on in the n1 The establishment of a CBR Application, as shown in Figure
Figure 9: Creating Application
Step7: Finally, set the simulation parameters (you can press the Parameters button or
shortcut keys Ctrl +6), in this case, because the script is to build a wired network, so
only some of the parameters to the simulation time (Simulation time ) Is set to 5.0, and
specify the file name to generate Trace, as shown in Figure 10.

Figure 10: Set simulation parameters


Step8: When everything has finished press the TCL set button (quick key Ctrl +7) to
generate script files
To generate the script file, and each will produce the script file is created in a separate
window, the user at this time can also be modified to do according to their needs, as
shown in Figure 11.

圖 11. 產生劇本檔

Step9:按下 Save 按鈕(快速鍵 Alt+S)將產生出來的 TCL 檔儲存起來之後,便可交由


ns2 開始進行模擬,產生出來的劇本檔如下 。

# This script is created by NSG2 beta1

# <http://wushoupong.googlepages.com/nsg>

#===================================

# Simulation parameters setup


#===================================

set val(stop) 5.0 ;# time of simulation


end

#===================================

# Initialization

#===================================

#Create a ns simulator

set ns [new Simulator]

#Open the NS trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

#Open the NAM trace file

set namfile [open out.nam w]

$ns namtrace-all $namfile

#===================================

# Nodes Definition

#===================================

#Create 6 nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]


#===================================

# Links Definition

#===================================

#Createlinks between nodes

$ns duplex-link $n0 $n2 2.0Mb 10ms DropTail

$ns queue-limit $n0 $n2 10

$ns duplex-link $n2 $n1 2.0Mb 10ms DropTail

$ns queue-limit $n2 $n1 10

$ns duplex-link $n4 $n3 2.0Mb 10ms DropTail

$ns queue-limit $n4 $n3 10

$ns duplex-link $n3 $n5 2.0Mb 10ms DropTail

$ns queue-limit $n3 $n5 10

$ns duplex-link $n2 $n3 1.0Mb 20ms DropTail

$ns queue-limit $n2 $n3 10

#Give node position (for NAM)

$ns duplex-link-op $n0 $n2 orient right-down

$ns duplex-link-op $n2 $n1 orient left-down

$ns duplex-link-op $n4 $n3 orient left-down

$ns duplex-link-op $n3 $n5 orient right-down

$ns duplex-link-op $n2 $n3 orient right

#===================================

# Agents Definition

#===================================

#Setup a UDP connection

set udp0 [new Agent/UDP]


$ns attach-agent $n0 $udp0

set null2 [new Agent/Null]

$ns attach-agent $n4 $null2

$ns connect $udp0 $null2

$udp0 set packetSize_ 1500

#Setup a UDP connection

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set null3 [new Agent/Null]

$ns attach-agent $n5 $null3

$ns connect $udp1 $null3

$udp1 set packetSize_ 1500

#===================================

# Applications Definition

#===================================

#Setup a CBR Application over UDP connection

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 1500

$cbr0 set rate_ 1.0Mb

$cbr0 set random_ null

$ns at 1.0 "$cbr0 start"

$ns at 4.0 "$cbr0 stop"

#Setup a CBR Application over UDP connection

set cbr1 [new Application/Traffic/CBR]


$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 1500

$cbr1 set rate_ 1.0Mb

$cbr1 set random_ null

$ns at 2.0 "$cbr1 start"

$ns at 3.0 "$cbr1 stop"

#===================================

# Termination

#===================================

#Define a 'finish' procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

$ns at $val(stop) "$ns nam-end-wireless $val(stop)"

$ns at $val(stop) "finish"

$ns at $val(stop) "puts \"done\" ; $ns halt"

$ns run

NSG arising out of the script file will automatically start NAM to render the simulation
process, if the NAM do not want to start setting the parameters in the NSG when the
NAM File option is set to -1, the NSG will not command the start NAM Which is written
to the script file. Figure 12 for the NAM start screen, can be seen in the simulation time
of 2.1 seconds, n2 due to the influx of too many packets while the packet is discarded
phenomenon occurs.
Following the interception of a Trace file part of the contents, the contents of the Trace
files can also be observed that the phenomenon of the packet is discarded (d on behalf
of drop).

前略
r 2.12 3 5 cbr 1500 ------- 0 1.0 5.0 2 88

r 2.12 0 2 cbr 1500 ------- 0 0.0 4.0 92 101

+ 2.12 2 3 cbr 1500 ------- 0 0.0 4.0 92 101

d 2.12 2 3 cbr 1500 ------- 0 0.0 4.0 92 101

- 2.12 2 3 cbr 1500 ------- 0 1.0 5.0 4 92

r 2.124 1 2 cbr 1500 ------- 0 1.0 5.0 9 102

+ 2.124 2 3 cbr 1500 ------- 0 1.0 5.0 9 102

r 2.128 2 3 cbr 1500 ------- 0 1.0 5.0 3 90

+ 2.128 3 5 cbr 1500 ------- 0 1.0 5.0 3 90

- 2.128 3 5 cbr 1500 ------- 0 1.0 5.0 3 90

+ 2.128 0 2 cbr 1500 ------- 0 0.0 4.0 94 105

- 2.128 0 2 cbr 1500 ------- 0 0.0 4.0 94 105

+ 2.132 1 2 cbr 1500 ------- 0 1.0 5.0 11 106

- 2.132 1 2 cbr 1500 ------- 0 1.0 5.0 11 106

r 2.132 3 4 cbr 1500 ------- 0 0.0 4.0 86 89


r 2.132 0 2 cbr 1500 ------- 0 0.0 4.0 93 103

+ 2.132 2 3 cbr 1500 ------- 0 0.0 4.0 93 103

d 2.132 2 3 cbr 1500 ------- 0 0.0 4.0 93 103

- 2.132 2 3 cbr 1500 ------- 0 0.0 4.0 88 93

r 2.136 1 2 cbr 1500 ------- 0 1.0 5.0 10 104

+ 2.136 2 3 cbr 1500 ------- 0 1.0 5.0 10 104

Listen
Read phonetically

Dictionary - View detailed dictionary


Listen
Read phonetically

Dictionary - View detailed dictionary


Listen
Read phonetically

S-ar putea să vă placă și