1. NS강좌(설치 및 기본예제)

Download Report

Transcript 1. NS강좌(설치 및 기본예제)

Network Simulator
- 1. 설치 및 기본 예제 LOGO
기술연구소 인터넷연구담당
손춘호 전임
Contents
1
개요
2
설치하기
3
간단한 예제
4
결과 분석
개요(1/3)
Network Simulator 2
 a Discrete event simulator
 Goals
• Support networking research and education
• Freely distributed, open source
– Share code, protocols, models, etc
 Link layer and up
 Wired and Wireless
개요(2/3)
NS Model
 Wired
•
•
•
•
•
•
Routing: DV, LS, PIM-SM etc.
Transportation: TCP and UDP
Traffic sources: web, ftp, telnet, cbr, stochastic etc.
Queuing disciplines: drop-tail, RED, FQ, SFQ, DRR etc.
QoS: IntServ and Diffserv …
Emulation
 Wireless
• Ad hoc routing, mobile IP and Satellite
• Directed diffusion, sensor-MAC
개요 (3/3)
Post-processing:
- simple trace analysis, often in Tcl, Awk or Perl
Pre-processing:
- Traffic and topology generators
- visualize ns (or other) output
설치하기 (1/5)
소스 구하기 (ns-allinone-2.29.tar.gz)
 ftp://ftp.isu.edu (하위디렉토리 /nsnam)
 http://www.isi.edu/nsnam/ns/
설치 플랫폼




Unix/Linux 계열 운영체제
(windows용 없음)
개인 폴더에 각자 설치 가능
운영체제 버전과 NS버전에 따라 설치시
에러발생가능
• 구글링을 통해서 해결
설치하기 (2/5)
 설치 예제 (Solaris 9 + GCC-3.4.1 + NS-2.29)
# ftp ftp.isi.edu (ftp / ftp)
ftp> cd nsnam
ftp> bin
ftp> hash
ftp> get ns-allinone-2.29.tar.gz
(Linux 일 경우)
ftp> quit
# tar zxvf ns-allinone-2.29.tar.gz
# gunzip –d ns-allinone-2.29.tar.gz
# tar xvf ns-allinone-2.29.tar
# cd ns-allinone-2.29
# ./install
설치하기 (3/5)
설치하기 (4/5)
설치 완료 후 마지막 로그
(환경 설정 관련 코멘트 확인)
설치하기 (5/5)
#####################################
# NS 2.29 setting
# NS Path : /user/sunshout/project
NS_DIR=/user/sunshout/project
쉘설정파일 수정
(.bash_profile)
개인설정에 맞게 수정(NS 상위디렉토리)
NS_PATH=$NS_DIR/ns-allinone-2.29/bin:$NS_DIR/ns-allinone2.29/tcl8.4.11/unix:$NS_DIR/ns-allinone-2.29/tk8.4.11/unix
# for shared library
OTCL=$NS_DIR/ns-allinone-2.29/otcl-1.11
NS_LIB=$NS_DIR/ns-allinone-2.29/lib
# for TCL library
TCL_LIBRARY=$NS_DIR/ns-allinone-2.29/tcl8.4.11/library
#################
# exporting all
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL:$NS_LIB
export TCL_LIBRARY
export PATH=$PATH:$NS_PATH
간단한 예제 (1/7)
NS 디렉토리 구조
ns-allinone
Tcl8.4
TK8.4
OTcl
tclcl
...
tcl
ex
examples
test
validation tests
ns-2
lib
nam-1 ...
C++ code
mcast
OTcl code
...
간단한 예제 (2/7)
시뮬레이션 Topology 구상
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
sink
간단한 예제 (3/7)
 시뮬레이션 코드 작성하기 (demo.tcl)
Text Log를
기록할 파일
생성
 초기화 (네트워크를 구성해 볼까!)
•
•
•
•
•
set ns [new Simulator]
set tr [open out.tr w]
set nr [open out.nam w]
$ns trace-all $tr
$ns namtrace-all $nr
Visual Log를
기록할 파일
생성
 노드 생성 (장비를 마렸했어요! – Physical Layer)
•
•
•
•
•
•
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
sink
간단한 예제 (4/7)
노드 연결(링크 생성)
 Links and queuing (장비들 간을 연결할까! – Link Layer)
• $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue_type>
• <queue_type>: DropTail, RED, CBQ, FQ, SFQ, DRR





$ns duplex-link $n0 $n2 10mb 2ms DropTail
$ns duplex-link $n1 $n2 10mb 2ms DropTail
$ns duplex-link $n2 $n3 5mb 15ms DropTail
$ns duplex-link $n3 $n4 10mb 2ms DropTail
$ns duplex-link $n3 $n5 10mb 2ms DropTail
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
sink
간단한 예제 (5/7)
프로토콜 설정
 에이전트 생성 (tcp / udp 결정 – Transport Layer)





set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $n1 $udp
$ns attach-agent $n5 $null
$ns connect $udp $null





set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
null
간단한 예제 (6/7)
Application 생성
 App 에이전트 생성 (ftp, http 등을 생성 – Application Layer)
 set cbr [new Application/Traffic/CBR]
 $cbr attach-agent $udp
 set ftp [new Application/FTP]
 $ftp attach-agent $tcp
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
null
간단한 예제 (7/7)
시뮬레이션 시간
 각 에이전트의 실행 시간 설정(모니터링 시간)
• $ns at <시간-초> “<에이전트 이름> start|stop”
• $ns run






$ns at 1.0 “$ftp start”
$ns at 2.0 “$cbr start”
$ns at 10.0 “$ftp stop”
$ns at 10.0 “$cbr stop”
$ns at 11.0 “finish”
proc finish { } {
global ns tr nr
$ns flush-trace
close $tr
close $nr
}
 $ns run
결과 분석 (1/2)
 실행
 # ns demo.tcl
 out.tr 과 out.nam 로그 파일이 생성
 GUI로 결과 보기
• # nam out.nam(눈요기거리)
결과 분석 (2/2)
Trace format
ftp
tcp
sink
n0
10Mb,2ms
n1
udp
cbr
n4
n2
5Mb, 15ms
n3
10Mb,2ms
n5
null
참조
NS Home page
 http://nsnam.isi.edu/nsnam/index.php/Main_Page
Trace format
 http://nsnam.isi.edu/nsnam/index.php/NS2_Trace_Formats
NS by Example
 http://nile.wpi.edu/NS/
LOGO