You are on page 1of 18

NSG

NSG
NSG ns2
NSG2NSG1 NSG2
NSG2 ns2

1.

2.

Node WirelessNode WiredNode

3.

WirelessNode

4.

Link Duplex-link Simplex-link

5.

Agent
TCPTCP/TahoeTCP/RenoTCP/NewrenoTCP/VegasTCPSinkUDP
NULL

6.

Application CBR FTP

7.

Routing protocol DSDVDSRAODV TORA

8.

Queue DropTailREDFQDRRSFQ CBQ

9.

10. 802.11 NSG 802.11b


NSG2 Java Java
WindowsLinuxMac OS ... NSG2 Java Jar
NSG2 NSG2 Java

NSG2 http://wushoupong.googlepages.com/nsg
NSG2 Java Runtime

EnvironmentJRE Java SE Development KitJDK Window


Java DOS java
-version Java Java
1

1. Java
JRE JDK Java
JRE JDK
JAVA http://java.sun.com/javase/downloads/index.jsp
NSG2 DOS NSG2
NSG2 C:\nsg2\ java -jar nsg2.jar 2

2. NSG2
NSG2
NSG2 NSG2

ns2
Node
...
.tcl ns2
NSG2
NSG2 NSG2
Node ns2
Node x,y,z
Node
NSG2 Node

NSG2 ns2
3
NSG2
1.

Hand mode

2.

Node mode

3.

Link mode

4.

Agent mode

5.

Application mode

3. NSG2
Hand mode
Hand mode
Node
Hand mode

Node mode
Node mode Node
Node NSG
Node NAM Node
Node Node
Routing protocol
NSG2 NSG
Node 250m
Node 250m NSG2
Node
Node Node mode Node

Chain Gridnn Random


Node Node
Link mode
Link mode Link
mode Node Node Simplex-link Duplex-link

Node

Agent mode
Agent mode Node ns2
Agent NSG2 TCP UDP
Node
Agent Agent Node

Agent mode Agent Node


Agent ns2
TCP Agent TCP-Sink Agent UDP Agent Null
Agent TCP Agent UDP Agent TCP-Sink Agent Null
Agent TCP Agent UDP Agent
TCP Agent TCP Agent
UDP Agent
Agent Agent
Agent Agent

Agent TCP congestion window


packet size
Application mode
Application mode CBR
FTP Agent
Application Application Agent

Agent Application
Application Application Application
Application
CBR Transmission rate packet size
Parameters

Trace NAM Trace


WirelessChannel
NSG2
802.11b

TCL TCL
ns2

1.

NSG

-1 -1
TCL NSG NSG
-50 NSG
2.

Node Node Link Node Agent


Agent Agent Application

3.

Agent TCL
Agent Agent

NSG
NSG
4

4.
Node
1.

n0 n4 UDP CBR cbr0

2.

n1 n5 UDP CBR cbr1

3.

n0-n2n1-n2n3-n4n3-n5 2Mbps 10ms

4.

n2-n3 1Mbps 20ms

5.

Duplex-link DropTail
Queue limit 10

1.

cbr0 1500bytes 1Mbps


1 4

2.

cbr1 1500bytes 1Mbps


2 3

3.

ns2 UDP 1000bytes


1000bytes UDP
Segmentation UDP
1500bytes UDP
cbr n2-n3
1Mbps cbr0 1Mbps n2-n3
cbr0 cbr1 n2-n3
n3
n3 cbr1

Step1 ScenarioNew wired


scenario Ctrl+W 5
NSG Node modeNode
Node

5.
Step2 Node Node
Node Node 6

6 : node
Step3 Node Link mode Link
Ctrl+3
1.

Link-typeduplex-link

2.

Queue typeDropTail

3.

Capacity2Mbps

4.

Propagation delay10ms

5.

Queue size10

Step4 n0-n2n1-n2n3-n4 n3-n5


Capacity 1MbpsPropagation delay 20ms
n2-n3 7

7 : node
Step5 Agent mode Agent Ctrl+4
Agent type UDP Packet size
1500 bytes n0 n1 Agent Agent type
NULL n4n5 NULL Agent Agent
Agent
Agentudp0null2udp1null3
8

8 : Agents
Step6 Application mode Application Ctrl+5
Application type CBR
Start time 1 Stop time 4
1500bytes 1Mbps n0 CBR
ApplicationStart time 2 Stop
time 3 n1 CBR Application 9

9 : Application
Step7 Parameters Ctrl+6

Simulation time 5.0 Trace


10

10:
Step8 TCL Ctrl+7


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
end
#===================================
#
Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

;# time of simulation

#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
$ns duplex-link-op $n2 $n1 orient
$ns duplex-link-op $n4 $n3 orient
$ns duplex-link-op $n3 $n5 orient
$ns duplex-link-op $n2 $n3 orient

right-down
left-down
left-down
right-down
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 NAM
NAM NSG NAM File -1 NSG
NAM 12 NAM
2.1 n2

12
Trace Trace
d 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