ns-2 간단한 예제1
ns-2 의 간단한 예제를 살펴보자. 노드의 구성은 아래 그림과 같다.

관련 소스는 아래와 같다.
주의사항: 줄번호가 들어간 것은 설명의 편의상 넣은 것이므로 파일로 다운받기 바랍니다.
1 #Create a simulator object
2 set ns [new Simulator]
3 #Open the nam trace file
4 set nf [open out.nam w]
5 $ns namtrace-all $nf
2 set ns [new Simulator]
3 #Open the nam trace file
4 set nf [open out.nam w]
5 $ns namtrace-all $nf
6 #Define a 'finish' procedure
7 proc finish {} {
8 global ns nf
9 $ns flush-trace
10 #Close the trace file
11 close $nf
12 #Execute nam on the trace file
13 exec nam out.nam &
14 exit 0
15 }
7 proc finish {} {
8 global ns nf
9 $ns flush-trace
10 #Close the trace file
11 close $nf
12 #Execute nam on the trace file
13 exec nam out.nam &
14 exit 0
15 }
16 #Create two nodes
17 set n0 [$ns node]
18 set n1 [$ns node]
17 set n0 [$ns node]
18 set n1 [$ns node]
19 #Create a duplex link between the nodes
20 $ns duplex-link $n0 $n1 1Mb 10ms DropTail
20 $ns duplex-link $n0 $n1 1Mb 10ms DropTail
21 #Create a UDP agent and attach it to node n0
22 set udp0 [new Agent/UDP]
23 $ns attach-agent $n0 $udp0
22 set udp0 [new Agent/UDP]
23 $ns attach-agent $n0 $udp0
24 # Create a CBR traffic source and attach it to udp0
25 set cbr0 [new Application/Traffic/CBR]
26 $cbr0 set packetSize_ 500
27 $cbr0 set interval_ 0.005
28 $cbr0 attach-agent $udp0
25 set cbr0 [new Application/Traffic/CBR]
26 $cbr0 set packetSize_ 500
27 $cbr0 set interval_ 0.005
28 $cbr0 attach-agent $udp0
29 #Create a Null agent (a traffic sink) and attach it to node n1
30 set null0 [new Agent/Null]
31 $ns attach-agent $n1 $null0
30 set null0 [new Agent/Null]
31 $ns attach-agent $n1 $null0
32 #Connect the traffic source with the traffic sink
33 $ns connect $udp0 $null0
33 $ns connect $udp0 $null0
34 #Schedule events for the CBR agent
35 $ns at 0.5 "$cbr0 start"
36 $ns at 4.5 "$cbr0 stop"
37 #Call the finish procedure after 5 seconds of simulation time
38 $ns at 5.0 "finish"
35 $ns at 0.5 "$cbr0 start"
36 $ns at 4.5 "$cbr0 stop"
37 #Call the finish procedure after 5 seconds of simulation time
38 $ns at 5.0 "finish"
39 #Run the simulation
40 $ns run
40 $ns run
ns-2 에서 tcl은 노드 생성 및 토플로지 구성, 시나리오 등의 비교적 변화의 여지가 많은 부분에서 사용된다.
반면에 c++는 실제 패킷을 어떻게 처리하는 등의 자주 변하지 않는 부분에서 사용된다.
위의 example1.tcl은 간단한 예제로서 두 노드 n0, n1 사이에 UDP를 이용해서 CBR 패킷을 보내는 시나리오이다.
2줄에서 새로운 시뮬레이터 객체를 선언한다. 시뮬레이션 수행을 위해선 반드시 필요한 부분이다.
4~5줄에서 nam 에니메이터로 보기 위한 파일을 설정하고 namtrace를 수행한다. 이 때, 중요한 것은 ns 객체가 선언된 다음에 위치해야 한다.
29~33줄은 n1에 null 에이전트를 생성 및 n1에 연결하는 작업이다. UDP는 TCP와는 다르게 ack를 보낼 필요가 없으므로 null 에이전트로 연결한다. 만약 TCP이면 tcpsink 를 사용함으로써 ack를 전송해야 한다.
반면에 c++는 실제 패킷을 어떻게 처리하는 등의 자주 변하지 않는 부분에서 사용된다.
위의 example1.tcl은 간단한 예제로서 두 노드 n0, n1 사이에 UDP를 이용해서 CBR 패킷을 보내는 시나리오이다.
2줄에서 새로운 시뮬레이터 객체를 선언한다. 시뮬레이션 수행을 위해선 반드시 필요한 부분이다.
4~5줄에서 nam 에니메이터로 보기 위한 파일을 설정하고 namtrace를 수행한다. 이 때, 중요한 것은 ns 객체가 선언된 다음에 위치해야 한다.
29~33줄은 n1에 null 에이전트를 생성 및 n1에 연결하는 작업이다. UDP는 TCP와는 다르게 ack를 보낼 필요가 없으므로 null 에이전트로 연결한다. 만약 TCP이면 tcpsink 를 사용함으로써 ack를 전송해야 한다.
http://www.joon.pe.kr/blog/trackback/2
http://xn--299aj0wmjfoqh97o.zxc700.com - 맞고사이트
http://xn--ok0b65d1w4aujecqm.zxc700.com - 정선카지노후기
http://xn--o80bq1nhvkvsd7rhba.zxc700.com - 마카오카지노순위
http://xn--c79a67g3zy6dt4w.zxc700.com - 카지노검증사이트
http://xn--o80b67oh5az7z4wcn0j.zxc700.com - 모바일카지노
http://xn--oi2b43dh5aa317l40j.zxc700.com - 모바일바카라
http://xn--o80bz00bbzcu6f.zxc700.com - 카지노
http://xn--oi2b30ghxt.zxc700.com - 바카라
http://xn--o80b910a26eepc81il5g.zxc700.com - 카지노사이트
http://xn--oi2b30g3ueowi6mjktg.zxc700.com - 바카라사이트
http://xn--o80b27i69npibp5en0j.zxc700.com - 온라인카지노
http://xn--oi2ba146a24mbtbtvt.zxc700.com - 온라인바카라
http://xn--mp2bs6av7jp7brh74w2jv.zxc700.com - 슬롯머신사이트
http://xn--ij2bx6j77bo2kdi289c.zxc700.com - 블랙잭사이트
http://xn--on3b21eb4bmwh91q.zxc700.com - 바카라주소
http://et.vmm789.com - 온라인바카라
http://vmm789.com - 카지노사이트
http://tt.vmm789.com - 룰렛사이트
http://cc.vmm789.com - 바카라사이트
http://zxc.vmm789.com - 슬롯머신사이트
http://et.vmm789.com - 온라인바카라
http://vmm789.com - 카지노사이트
http://tt.vmm789.com - 룰렛사이트
http://cc.vmm789.com - 바카라사이트
http://zxc.vmm789.com - 슬롯머신사이트
http://et.vmm789.com - 온라인바카라
http://vmm789.com - 카지노사이트
http://tt.vmm789.com - 룰렛사이트
http://cc.vmm789.com - 바카라사이트
http://zxc.vmm789.com - 슬롯머신사이트
http://et.vmm789.com - 온라인바카라
http://vmm789.com - 카지노사이트
http://tt.vmm789.com - 룰렛사이트
http://cc.vmm789.com - 바카라사이트
http://zxc.vmm789.com - 슬롯머신사이트