zoukankan      html  css  js  c++  java
  • NS 2.35 柯志亨书实验4笔记随机数产生

    上图是笔记。

    测试了3条ftp流时,链路的吞吐量
    通过采用不同的随机启动时间,得到不同的试验结果,可以平均一下

    tcl代码:

    View Code
    # Kezhiheng, experiment 4, test RNG, 3 tcp flow
    
    #Create a simulator object
    set ns [new Simulator]
    
    set tracefd [open out.tr w]
    $ns trace-all $tracefd
    set namtracefd [open out.nam w]
    $ns namtrace-all $namtracefd
    
    proc finish {} {
            global ns tracefd namtracefd
            $ns flush-trace
            close $tracefd
            close $namtracefd
        #    exec nam out.nam &
            exit 0
    }
    
    # 3 TCP flow
    set nflow 3
    
    # Set router nodes
    set r1 [$ns node]
    set r2 [$ns node]
    $ns duplex-link $r1 $r2 1Mb 10ms DropTail
    $ns queue-limit $r1 $r2 10
    
    # Set TCP src, dest, link
    for {set i 1} {$i<=$nflow} {incr i} {
        set s($i) [$ns node]
        set d($i) [$ns node]
        
        $ns duplex-link $s($i) $r1 10Mb 1ms DropTail
        $ns duplex-link $r2 $d($i) 10Mb 1ms DropTail
    }
    
    # Set TCP agent and FTP traffic
    for {set i 1} {$i<=$nflow} {incr i} {
        set tcp($i)  [new Agent/TCP]
        set sink($i) [new Agent/TCPSink]
        $ns attach-agent $s($i) $tcp($i)
        $ns attach-agent $d($i) $sink($i)
        $ns connect $tcp($i) $sink($i)
    
        set ftp($i) [new Application/FTP]
        $ftp($i) attach-agent $tcp($i)
        $ftp($i) set type_ FTP
    }
    
    set rng [new RNG]
    $rng seed 5
    
    set rvStart [new RandomVariable/Uniform]
    $rvStart use-rng $rng
    $rvStart set min_ 0.0
    $rvStart set max_ 1.0
    
    for {set i 1} {$i<=$nflow} {incr i} {
        set startT($i) [expr [$rvStart value]]
    #    puts "startT($i) $startT($i) sec"
        set endT($i) [expr ($startT($i)+5)]
    #    puts "endT($i) $endT($i) sec"
        
        $ns at $startT($i) "$ftp($i) start"
        $ns at $endT($i)   "$ftp($i) stop"
    }
    
    $ns at 7.0 "finish"
    
    $ns run

    awk代码:

    View Code
    # Measure the throughput by the trace file
    
    BEGIN{
        # program initialize
        init = 0;
        startT=0;
        endT=0;
    }
    
    {
    
    action = $1;
    time = $2;
    from = $3;
    to = $4;
    type = $5;
    pktsize = $6;
    flow_id = $8;
    src = $9;
    dst = $10;
    seq_no = $11;
    packet_id = $12;
    
    # Record pkttype=tcp, action=r, time 1s~5s
    if(action=="r" && type=="tcp" && time>=1.0 && time<=5.0 && \
        ( (from==1 && to==3)||(from==1 && to==5)||(from==1 && to==5) ) )
    {
        if(init==0)
        {
            startT = time;
            init = 1;
        }
        pkt_byte_sum += pktsize;
        endT=time;
    }
    
    }
    
    END {
    # When read over, start to calculate
    printf("startT:%f,endT:%f\n",startT,endT);
    printf("pkt_byte_sum:%d\n",pkt_byte_sum);
    time = endT-startT;
    throughput=pkt_byte_sum * 8 / time / 1000000;
    printf("throughput:%.3f Mbps\n", throughput);
    }

    执行shell代码:

    View Code
    #!/bin/bash
    
    ns rng_tcp.tcl
    
    awk -f rng_tcp.awk out.tr

    ftp flow为3条的测试结果:

    View Code
    -------------------------------
    seed=1
    startT:1.025972,endT:4.977268
    pkt_byte_sum:266280
    throughput:0.539 Mbps
    -------------------------------
    seed=2
    startT:1.005634,endT:4.992002
    pkt_byte_sum:353600
    throughput:0.710 Mbps
    -------------------------------
    seed=3
    startT:1.000912,endT:4.999952
    pkt_byte_sum:320320
    throughput:0.641 Mbps
    -------------------------------
    seed=4
    startT:1.003102,endT:4.999262
    pkt_byte_sum:246480
    throughput:0.493 Mbps
    -------------------------------
    seed=5
    startT:1.009901,endT:4.996269
    pkt_byte_sum:271440
    throughput:0.545 Mbps

    可完善地方:
    如果ns xxx.tcl
    这句可以带参数,那么就可以在shell中,写循环测试不同数量ftp流的吞吐率了
    外层循环使用ftp流的数量
    内层循环使用随机数种子

    后面将寻找实现方法,这样可以节省许多功夫,有谁知道的,要分享一下哦~

  • 相关阅读:
    Rose2003执行出现 -2147417848 (80010108)&#39;:Automation 错误
    Xcode 证书生成、设置、应用
    关于数组中加入相同的view的试验
    XCode 项目配置说明
    ios申请真机调试( xcode 5)详细解析
    CAShapeLayer--备用
    手把手教你 iOS通过自己的服务器实现应用分发
    iOS最新上线流程+续费 2015-7-20更新
    iOS8的一些控件的变更
    iOS8上放大缩小的动画
  • 原文地址:https://www.cnblogs.com/yanhc/p/3074051.html
Copyright © 2011-2022 走看看