suakii.egloos.com

suakii's log





NS2 대역폭에 따른 패킷 Drop Rate 변화 공부

지난번부터 꼭 해보고 싶었던 작업이 하나 있었다. 그동안은 그것을 수행하기 위한 지식이 부족하여 마음속으로만 생각해오다가 오늘 간단하게 테스트를 할 수 있었다. 주제는 대역폭에 따른 노드에서의 패킷 Drop Rate을 보려고 하는 것이다. Topology는 아래와 같다. 패킷의 Drop에 관하여 다른 조건은 고려하지 않고 오직 node2 - node3사이의 대역폭의 변화가 미치는 영향만을 보았다.
작업의 진행순서는 tcl 코드 작성 후 노드2-3의 대역폭을 변수로 설정 한 후 shell script에서 대역폭값을 변화시키면서 ns2를 호출하였고 다시금 perl script가 작업을 하여서 결과를 보여주는 식으로 하였다.

1. Topology



2. Tcl Code
#Create a simulator object
set ns [new Simulator]

set bw    [lindex $argv 0]

#Define different colors for data flows
$ns color 1 Blue
$ns color 2 Red

#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Open the trace file
set tf [open out.tr w]
$ns trace-all $tf

#Define a 'finish' procedure
proc finish {} {
        global ns nf tf
        $ns flush-trace
    #Close the trace file
        close $nf
    close $tf
    #Execute nam on the trace file
        #exec nam out.nam &
        exit 0
}

#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 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 $bw 10ms SFQ

$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $n2 $n3 queuePos 0.5

#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

#Create a UDP agent and attach it to node n1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1

# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1

#Create a Null agent (a traffic sink) and attach it to node n3
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0

#Connect the traffic sources with the traffic sink
$ns connect $udp0 $null0 
$ns connect $udp1 $null0

#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"

#Run the simulation
$ns run


3. Shell Script(분명히 아래의 list를 증가시키는 방법이 있을텐데 몰라서 그냥 무식하게 다 썻다.ㅠ.ㅠ)
#!/bin/bash
bw_array='0.1Mb 0.2Mb 0.3Mb 0.4Mb 0.5Mb 0.6Mb 0.7Mb 0.8Mb 0.9Mb 1.0Mb 1.1Mb 1.2Mb 1.3Mb 1.4Mb 1.5Mb 1.6Mb 1.7Mb'
rm -rf *.txt
for bw_size in $bw_array
do
  
    echo "Working $bw_size.... "

    ns example2.tcl $bw_size
    perl drop_node.pl "drop_vs_bw_${bw_size}.txt"
done
xgraph *.txt &


4. Perl Script(Perl은 이번이 처음이다.ㅠ.ㅠ)
open TR2, ">>$ARGV[0]";
open TR, "out.tr";

$drop_count = 0;
@row = undef;

while(<TR>)
{
    @row = split;
    if ($row[0] eq "d")
    {
        if($row[2] eq "2")
        {
            if($row[3] eq "3")
            {
                $drop_count++;
                $drop_rate = $drop_count/$row[1];
                print TR2 "$row[1] $drop_rate\n";
            }
        }

    }
}
close TR;
close TR2;


5. xgraph 결과(대역폭이 1.6Mb 부터는 Drop이 발생하지 않음)

p.s 오류가 없는 코드들이라면 보여주는 결과는 어느정도 예상한것과 일치하고 있다. 사실 별다를것 없는 코드들이지만 파라미터 값을 변화시키면서 시뮬레이션을 하려면 shell script를 이용할 수 밖에 없다. 그것을 배웠다는것에 만족하고 이전의 awk 코드가 아닌 perl을 사용했다는 것에 또 만족해야 하는 정도랄까. 자 이제는 LAN Simulation에서의 각종 수치들을 볼 수 있는 작업을 하는 것이 다음 목표다. 사실 ns2의 진정한 사용은 프로토콜 설계에 있으리라는 생각이 드는데 거기까진 제반 환경이 허락하지를 않을 것 같다. 잘 된건지 안된건지 모르겠지만....

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://suakii.egloos.com/tb/2465354 [도움말]

덧글

  • 짜이 2009/11/04 23:12 # 삭제 답글

    또 아름다운 그래프를~ 자꾸자꾸 보다 보면 언젠간 나도 예술 하고 싶어지려나?
  • 수아기 2009/11/05 23:54 #

    이미 예술을 하고 계시면서~~
덧글 입력 영역