NS2 스크립트 - 유선환경 시뮬레이션

|
# Simulator 인스턴스 생성 후 ns 할당
# Simulator는 단 한개 존재
set ns [new Simulator] ;
 
#trace할 파일 열기
set trace [open basic_ex.tr w]
# tr trace
$ns trace-all $trace
#x-window를 지원하는 trace
set namtrace [open basic_ex.nam w]
$ns namtrace-all $namtrace
#node는 simulator의 멤버 함수
#Node 인스턴스 생성 후 n0, n1에 할당
set n0 [$ns node]
set n1 [$ns node]
#duplex-link는 simulator의 멤버 함수
#duplex-link <노드1> <노드2> <대역폭> <딜레이> <큐타입>
#$n0 $n1 10Mb 2ms DropTail은 인수들
#노드 n0 노드 n1 사이에 양방향 링크 생성
$ns duplex-link $n0 $n1 10Mb 2ms DropTail
#Agent/UDP 인스턴스 생성 후 udp0에 할당
#Agent/UDP는 Agent를 상속
#UDP : 비신뢰 전송
#TCP : 신뢰 전송, 전송 제어
# 생성 : set tcp0 [new Agent/TCP] #(Tahoe), set tcp1 [new Agent/TCP/Reno], set tcp2 [new Agent/TCP/newReno]
set udp0 [new Agent/UDP]

#attach-agnet는 simulator의 멤버함수
#$n0 $udp0는 인수들
#$n0에 $udp0를 부착 (스택을 쌓아 올림)
$ns attach-agent $n0 $udp0

#Application/Traffic/CBR 인스턴스 생성후
#cbr0에 할당
#CBR(Constant Bit Rate) : 정해진 패킷 크기로 정해진 주기로 전송
#CBR 주요 속성 : packetSize_(패킷크기, 단위 Byte), interval_(패킷 전송간격, 단위는 sec), rate_
#FTP(File Transfer Protocol) : 무한 크기의 파일 전송
#FTP 생성 : set ftp0 [new Application/FTP]
set cbr0 [new Application/Traffic/CBR]

#attach-agent는 CBR/Traffic/CBR의 멤버 함수가 아니다.
$cbr0 attach-agent $udp0
#Agent/Null 인스턴스 생성 후 null0에 할당
#Agent/Null은 Agent를 상속
#Null : 패킷을 받는 일만 함, UDP의 수신자 역확을 함
#TCP 수신은 TCPSink로 함 : set tcp0 [new Agent/TCPSink]
set null0 [new Agent/Null]

#$n1에 $null0 부착 (스택을 쌓아올림)
$ns attach-agent $n1 $null0
#connect는 Simulator의 멤버 함수
#udp0 $null0는 인수들
#인수로 받은 에이전트들을 연결함
# connetc <srcAgent> <dstAgent>
$ns connect $udp0 $null0
#at은 Simulator의 멤버 함수
#at <시간> <명령어> : 시뮬레이션상의 '시간'에 '명령어'실행 (now:시뮬레이션 상의 가상시간 리턴)
#인자로 시간과 명령어가 옴
#명령어에 공백이 있는 경우 ""
#실시간이 아닌 virtual time임
#halt : simulation 종료
$ns at 1.0 "$cbr0 start"
$ns at 10.0 "$ns halt"
#run은 Simulator의 멤버함수
#스케쥴된 이벤트 시작
#하앙 맨마지막에 실행
$ns run

'Network > Ns2_Lecture' 카테고리의 다른 글

NS2 trace  (0) 2009.01.18
awk  (0) 2009.01.18
Description of the ns-2 modifications  (0) 2009.01.18
5.3 Node Configuration Interface  (0) 2009.01.18
ns-2 Software and Simulation Results  (0) 2009.01.18
And