1 / 23

Network Simulator 2

Network Simulator 2. 성균관대학교 모바일컴퓨팅 연구실 http://csn.skku.ac.kr 안 혜환 hyehwan @ ece.skku.ac.kr. 목차. NS-2 역사 NS-2 설치 방법 NS-2 사용 목적 NS – 2 동작 원리 더욱 간단한 NS-2 동작원리 왜 2 가지 언어를 사용하는가 ? NS, Otcl, C++ 와의 관계 간단한 OTcl 과 복잡한 C++ NS, Otcl, C++ 의 디렉토리 위치 소스 코드 상속 구조 새로운 요소 추가시 컴파일 방법 이벤트 스케쥴러

Télécharger la présentation

Network Simulator 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network Simulator 2 성균관대학교 모바일컴퓨팅 연구실 http://csn.skku.ac.kr 안 혜환 hyehwan@ece.skku.ac.kr

  2. 목차 • NS-2역사 • NS-2설치 방법 • NS-2사용 목적 • NS – 2 동작 원리 • 더욱 간단한NS-2동작원리 • 왜 2 가지 언어를 사용하는가? • NS, Otcl, C++와의 관계 • 간단한OTcl과복잡한C++ • NS, Otcl, C++의 디렉토리 위치 • 소스 코드 상속 구조 • 새로운 요소 추가시 컴파일 방법 • 이벤트 스케쥴러 • 간단한 예제 • 간단한 시뮬레이션 코드 구성방식 • 시뮬레이션 영상툴NAM • 성능평가를 위한 파일 추출 및 파일 내부 • 성능평가를 위한 파일로 부터 그래프 그리기 1/2 • 성능평가를 위한 파일로 부터 그래프 그리기 2/2 • 참고 자료

  3. NS-2역사 • 1989 년 REAL network simulator의 세부연구로 시작. • 여러 기관이 참여하는 (LBL, Xerox, PARC, UCB, USC/ISI) VINT (Virtual InterNetwork Testbed ) 프로젝트 를 통해 DARPA 의 지원으로 1995 NS개발 시작 • 현재 NS개발은 CONSER (Collaborative Simulation for Education and Research) 과 함께 NSF를 통해 SAMAN(Simulation Agumented by Measurement and Analysisfor Networks)과 함게 DARPA를 통해 지원하고 있다.

  4. NS-2설치 방법 [데모 시청] • Windows, Linux, FreeBSD 등등 여러 플렛폼을 지원하나 리눅스를 권장. • http://www.isi.edu/nsnam/dist/에 가서 원하고자 하는 NS 버전을 다운. • 다운받을화일 “ns-allinone-2.xx.tar.gz”를 적당한 위치에 압출을 푼다. • 압축을 푼 곳에 가서 “./install”이라고 입력함으로 인해서 설치를 완료. • GCC 버전 문제로 컴파일 에러가 날수 있으니 리눅스 에 설치시 wowlinux 7.3 이나 레드헷 7.3 버전에는 설치하는 것을 권장함 .

  5. NS-2사용 목적 • 왜 NS-2 를 사용하는가 ?- 공식적인 기관이나 단체가 연합하여 제작- 매우 신뢰성 있는 성능평가 • 큰 사이즈의 네트워크 성능평가- 실제로 성능평가 할 경우 매우 많은 경비와 시간이 소모 되나 시뮬레이션 툴을 사용함으로 인해서 경비절감 • 새로운 프로토콜 성능평가- 새로운 프로토콜의 검증 - 자신의 새로운 아이디어 성능평가

  6. NS – 2 동작 원리 1/2 Scheduling • #Create a simulator object • set ns [new Simulator] • #Create four nodes • set n0 [$ns node] • set n1 [$ns node] • set n2 [$ns node] • set n3 [$ns node] • #Create links between the nodes • $ns duplex-link $n0 $n2 2Mb 10ms DropTail • $ns duplex-link $n1 $n2 2Mb 10ms DropTail • $ns duplex-link $n2 $n3 1.7Mb 20ms DropTail • #Set Queue Size of link (n2-n3) to 10 • $ns queue-limit $n2 $n3 10 • #Setup a TCP connection • set tcp [new Agent/TCP] • $tcp set class_ 2 • $ns attach-agent $n0 $tcp • set sink [new Agent/TCPSink] • $ns attach-agent $n3 $sink • $ns connect $tcp $sink • $tcp set fid_ 1 • #Schedule events for the CBR and FTP agents • $ns at 0.1 "$cbr start" • $ns at 1.0 "$ftp start" • $ns at 4.0 "$ftp stop" • $ns at 4.5 "$cbr stop" • #Call the finish procedure after 5 seconds of simulation time • $ns at 5.0 "finish" • #Run the simulation • $ns run Otcl (내부동작) Event Otcl (외부동작) C++(내부동작)

  7. NS – 2 동작 원리 2/2 • 코드 작성시 반드시 알고 있어야 할 동작 원리 • ns 내부에서 Thread 등의 사용 금지 NS 와 OS 간 코드 동작원리 Windows 코드 동작원리

  8. 더욱 간단한NS-2동작원리 확률 분포에 따른 주기적 패킷 생성 트래픽 생성기 코드 위치 Ns-allinonexxx/ns-2.xx/tcl/lib/ns-source.tcl

  9. NS, Otcl, C++와의 관계

  10. 간단한OTcl과복잡한C++[전지 분석 자료 참고] C++ 코드 NODE.cc #include <stdio.h> #include <stdarg.h> #include "address.h" #include "config.h" #ifdef HAVE_STL #include "nix/nixnode.h" #endif //HAVE_STL #include "node.h" static class LinkHeadClass : public TclClass { public: LinkHeadClass() : TclClass("Connector/LinkHead") {} TclObject* create(int, const char*const*) { return (new LinkHead); } } class_link_head; LinkHead::LinkHead() : net_if_(0), node_(0), type_(0) { } int32_t LinkHead::label() { if (net_if_) return net_if_->intf_label(); printf("Configuration error: Network Interface missing\n"); exit(1); // Make msvc happy return 0; } ………………….. OTcl 코드 #Create a simulator object set ns [new Simulator] #Create four nodes set n0 [$ns node] .....................

  11. NS, Otcl, C++의 디렉토리 위치 ☞ 2 가지 기능을 가지는 TCL 의 위치 1. 시뮬레이션 구성 2. C++ 여러 객체 구성 해서 새로운 객체를 생성(부록 1) ☞ 모든 C++ 코드는 이곳에 위치

  12. 소스 코드 상속 구조 TclObject Scheduler NsObject Node Process Connector Classifier Application FTP Queue Delay Agent Trace AddrClassifier DropTail RED TCP Enq Deq Drop PortClassifier Reno SACK Vegas

  13. 새로운 요소 추가시 컴파일 방법 • xxx.cc C++ 코드 추가시- “ns-allinone2.xx/ns-2.xx/Makefile”내부에“OBJ_CC = xxx.o” 추가 • xxx.h header 코드 추가시- 추가 한후 새로운 패킷 타입이 다루는 자료구조 선언 • xxx.tcl OTcl 라이브 러리 추가시- “ns-allinone2.xx/ns-2.xx/Makefile”내부에 “NS_TCL_LIB=xxx.tcl” 추가 • 새로운 Application 추가시- “ns-allinone2.xx/ns-2.xx/packet.h” 내부에 “PT_NEW” 패킷 타입 추가

  14. 이벤트 스케쥴러 • Create event scheduler • set ns [new Simulator] • Schedule events (OTcl) • OTcl: $ns at <time> <TCL_command> • C++: Scheduler::schedule(h,e, delay) - 2가지 용도로 사용됨 - 독립된 노드 실행- Thread 대치 용도 • Obtain simulation time • OTcl: $ns now • C++: Scheduler::clock() • Start scheduler • $ns run

  15. 간단한 예제 (데모 시청] 스케줄러 생성 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 set null1 [new Agent/Null] $ns attach-agent $n1 $null1 $ns connect $udp0 $null0 $ns connect $udp1 $null1 $ns at 1.0 "$cbr0 start" $ns at 1.1 "$cbr1 start" set tcp [new Agent/TCP] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $n0 $tcp $ns attach-agent $n3 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 1.2 "$ftp start" $ns at 1.35 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" puts [$cbr0 set packetSize_] puts [$cbr0 set interval_] $ns at 3.0 "finish" proc finish {} { global ns f nf $ns flush-trace close $f close $nf puts "running nam..." exec nam out.nam & exit 0 } $ns run set ns [new Simulator] $ns color 0 blue $ns color 1 red $ns color 2 white set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set f [open out.tr w] $ns trace-all $f set nf [open out.nam w] $ns namtrace-all $nf $ns duplex-link $n0 $n2 5Mb 2ms DropTail $ns duplex-link $n1 $n2 5Mb 2ms DropTail $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail $ns duplex-link-op $n0 $n2 orient right-up $ns duplex-link-op $n1 $n2 orient right-down $ns duplex-link-op $n2 $n3 orient right $ns duplex-link-op $n2 $n3 queuePos 0.5 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 set udp1 [new Agent/UDP] $ns attach-agent $n3 $udp1 $udp1 set class_ 1 set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 에이젼트 생성 노드생성 트레이스 에플리 케이션 생성 링크생성 시뮬레이션종료 에이젼트 생성 시뮬레이션시작

  16. 간단한 시뮬레이션 코드 구성방식 • 스케쥴러 생성 • 노드 생성 • 트레이스 파일 생성 • 링크 생성 • 에이전트 생성 • 에플리케이션 생성 • 시뮬레이션 이벤트 생성 • 시뮬레이션 시작 • 시뮬레이션 종료 함수 생성

  17. 시뮬레이션 영상툴NAM [데모 시청] • NAM파일 생성……..set f [open out.tr w]$ns trace-all $fset nf [open out.nam w]$ns namtrace-all $nf…….. • NAM파일을 통한 시뮬레이션 영상 재생nam out.nam

  18. 성능평가를 위한 파일 추출 및 파일 내부 • $ns trace-all [open out.trw]

  19. 성능평가를 위한 파일로 부터 그래프 그리기 1/2 기존 방법 • 스크립트를 이용하여 tr 파일로 부터 그래프 파라미터 추출 • 스크립트후 나온 결과를 xgraph사용하여 표현 • 예제 cat out.tr | grep " 2 3 cbr " | grep ^r | column 1 10 | awk '{dif = $2 - old2; if(dif==0) dif = ; if(dif > 0) {printf("%d\t%f\n", $2, ($1 - old1) / dif); old1 = $1; old2 = $2}}' > jitter.txt

  20. 성능평가를 위한 파일로 부터 그래프 그리기 2/2 [데모 시청] 새로운 방법 • Matlab 6.0 이상 에서 운영되는 새로나온 tracegraph202 라는 툴 사용(단점 : 1000 라인 이상 트레이스 파일 처리 못함) • 자료 위치http://www.geocities.com/tracegraph/

  21. 참고 자료 • Ns Manual- http://www.isi.edu/nsnam/ns/ns-documentation.html • Tcl - uist course: http://www.cs.huji.ac.il/~uist • OTcl • http://www.isi.edu/nsnam/otcl/README.html • NS-2 - http://www.isi.edu/nsnam/ns/tutorial/index.html - http://www.isi.edu/nsnam/ns/ • Trace Tool- http://www.geocities.com/tracegraph/

  22. 감사 합니다.Q & A

  23. 부록 1. ns-mobilenode.tcl

More Related