1. 程式人生 > >無線網路中吞吐量、丟包率、端到端時延的測量

無線網路中吞吐量、丟包率、端到端時延的測量

#
#
#
#===================================================================
# Define Node Configuration paramaters
#===================================================================
set val(chan)           Channel/WirelessChannel    ;# channel type
set val(prop)           Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)          Phy/WirelessPhy            ;# network interface type
set val(mac)            Mac/802_11                ;# MAC type
set val(ifq)            Queue/DropTail/PriQueue   ;# interface queue type
set val(ll)             LL                         ;# link layer type
set val(ant)            Antenna/OmniAntenna        ;# antenna model
set val(ifqlen)         50                         ;# max packet in ifq
set val(nn)             8                          ;# number of mobilenodes
set val(rp)             DSDV                       ;# routing protocol
set val(x)              500                        ;# X dimension of the topography
set val(y)              500                        ;# Y dimension of the topography
Mac/802_11 set RTSThreshold_  3000
Mac/802_11 set basicRate_ 1Mb
Mac/802_11 set dataRate_  2Mb
#=====================================================================
# Initialize trace file desctiptors
#=====================================================================
# *** Throughput Trace ***
set f0 [open out02.tr w]
set f1 [open out12.tr w]
set f2 [open out22.tr w]
set f3 [open out32.tr w]
# *** Packet Loss Trace ***
set f4 [open lost02.tr w]
set f5 [open lost12.tr w]
set f6 [open lost22.tr w]
set f7 [open lost32.tr w]
# *** Packet Delay Trace ***
set f8 [open delay02.tr w]
set f9 [open delay12.tr w]
set f10 [open delay22.tr w]
set f11 [open delay32.tr w]

#以下部分的程式碼,在 入門例項2 中已有詳盡的註釋啦!
set ns_ [new Simulator]
set tracefd   [open trace2.tr w]
$ns_ trace-all $tracefd
set namtrace [open sim12.nam w]
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)

set topo [new Topography]
$topo load_flatgrid 500 500
 
# Create  General Operations Director (GOD) object.
#It is used to store global information about the state of the environment, network, or nodes that an
# omniscent observer would have, but that should not be made known to any participant in the simulation.
 
create-god $val(nn)
# configure nodes
        $ns_ node-config -adhocRouting $val(rp) /
                         -llType $val(ll) /
                         -macType $val(mac) /
                         -ifqType $val(ifq) /
                         -ifqLen $val(ifqlen) /
                         -antType $val(ant) /
                         -propType $val(prop) /
                         -phyType $val(netif) /
                         -channelType $val(chan) /
                         -topoInstance $topo /
                         -agentTrace ON /
                         -routerTrace ON /
                         -macTrace OFF /
                         -movementTrace OFF                   

# Create Nodes
        for {set i 0} {$i < $val(nn) } {incr i} {
                set node_($i) [$ns_ node]
                $node_($i) random-motion 0            ;# disable random motion
        }
# Initialize Node Coordinates
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0
$node_(1) set Y_ 5.0
$node_(1) set Z_ 0.0

$node_(2) set X_ 5.0
$node_(2) set Y_ 50.0
$node_(2) set Z_ 0.0

$node_(3) set X_ 200.0
$node_(3) set Y_ 50.0
$node_(3) set Z_ 0.0
 
$node_(4) set X_ 5.0
$node_(4) set Y_ 100.0
$node_(4) set Z_ 0.0

$node_(5) set X_ 200.0
$node_(5) set Y_ 100.0
$node_(5) set Z_ 0.0

$node_(6) set X_ 2.0
$node_(6) set Y_ 150.0
$node_(6) set Z_ 0.0

$node_(7) set X_ 200.0
$node_(7) set Y_ 150.0
$node_(7) set Z_ 0.0

# Setup traffic flow between nodes
# TCP connections between node_(0) and node_(1)
# Create Constant four Bit Rate Traffic sources
#============================================================
#以下的這段程式碼可以寫成一個過程,那樣就方便多啦!
#先整理, 以後我再回頭改吧!
#============================================================
set agent1 [new Agent/UDP]              ;# Create TCP Agent
$agent1 set prio_ 0                     ;# Set Its priority to 0
# Create Loss Monitor Sink in order to be able to trace the number obytes received

set sink [new Agent/LossMonitor]       
$ns_ attach-agent $node_(0) $agent1     ;# Attach Agent to source node
$ns_ attach-agent $node_(1) $sink       ;# Attach Agent to sink node
$ns_ connect $agent1 $sink              ;# Connect the nodes
set app1 [new Application/Traffic/CBR]  ;# Create Constant Bit Rate application
$app1 set packetSize_ 512               ;# Set Packet Size to 512 bytes
$app1 set rate_ 600Kb                   ;# Set CBR rate to 200 Kbits/sec
$app1 attach-agent $agent1              ;# Attach Application to agent

set agent2 [new Agent/UDP]              ;# Create TCP Agent
$agent2 set prio_ 1                     ;# Set Its priority to 1
# Create Loss Monitor Sink in order to be able to trace the number obytes received
set sink2 [new Agent/LossMonitor]        
$ns_ attach-agent $node_(2) $agent2     ;# Attach Agent to source node
$ns_ attach-agent $node_(3) $sink2      ;# Attach Agent to sink node
$ns_ connect $agent2 $sink2             ;# Connect the nodes
set app2 [new Application/Traffic/CBR]  ;# Create Constant Bit Rate application
$app2 set packetSize_ 512               ;# Set Packet Size to 512 bytes
$app2 set rate_ 600Kb                   ;# Set CBR rate to 200 Kbits/sec
$app2 attach-agent $agent2              ;# Attach Application to agent

set agent3 [new Agent/UDP]              ;# Create TCP Agent
$agent3 set prio_ 2                     ;# Set Its priority to 2
# Create Loss Monitor Sink in order to be able to trace the number obytes received
set sink3 [new Agent/LossMonitor]        
$ns_ attach-agent $node_(4) $agent3     ;# Attach Agent to source node
$ns_ attach-agent $node_(5) $sink3      ;# Attach Agent to sink node
$ns_ connect $agent3 $sink3             ;# Connect the nodes
set app3 [new Application/Traffic/CBR]  ;# Create Constant Bit Rate application
$app3 set packetSize_ 512               ;# Set Packet Size to 512 bytes
$app3 set rate_ 600Kb                   ;# Set CBR rate to 200 Kbits/sec
$app3 attach-agent $agent3              ;# Attach Application to agent

set agent4 [new Agent/UDP]              ;# Create TCP Agent
$agent4 set prio_ 3                     ;# Set Its priority to 3
# Create Loss Monitor Sink in order to be able to trace the number obytes received
set sink4 [new Agent/LossMonitor]        
$ns_ attach-agent $node_(6) $agent4     ;# Attach Agent to source node
$ns_ attach-agent $node_(7) $sink4      ;# Attach Agent to sink node
$ns_ connect $agent4 $sink4             ;# Connect the nodes
set app4 [new Application/Traffic/CBR]  ;# Create Constant Bit Rate application
$app4 set packetSize_ 512               ;# Set Packet Size to 512 bytes
$app4 set rate_ 600Kb                   ;# Set CBR rate to 200 Kbits/sec
$app4 attach-agent $agent4              ;# Attach Application to agent

# defines the node size in Network Animator
for {set i 0} {$i < $val(nn)} {incr i} {
    $ns_ initial_node_pos $node_($i) 20
}

# Initialize Flags
set holdtime 0
set holdseq 0

set holdtime1 0
set holdseq1 0

set holdtime2 0
set holdseq2 0

set holdtime3 0
set holdseq3 0

set holdrate1 0
set holdrate2 0
set holdrate3 0
set holdrate4 0

# Function To record Statistcis (Bit Rate, Delay, Drop)
proc record {} {
        global sink sink2 sink3 sink4 f0 f1 f2 f3 f4 f5 f6 f7 holdtime holdseq holdtime1 holdseq1 holdtime2 holdseq2 holdtime3 holdseq3 f8 f9 f10 f11 holdrate1 holdrate2 holdrate3 holdrate4
        set ns [Simulator instance]
    set time 0.9 ;#Set Sampling Time to 0.9 Sec
        set bw0 [$sink set bytes_]
        set bw1 [$sink2 set bytes_]
        set bw2 [$sink3 set bytes_]
        set bw3 [$sink4 set bytes_]
        set bw4 [$sink set nlost_]
        set bw5 [$sink2 set nlost_]
        set bw6 [$sink3 set nlost_]
        set bw7 [$sink4 set nlost_]
        set bw8 [$sink set lastPktTime_]
        set bw9 [$sink set npkts_]
        set bw10 [$sink2 set lastPktTime_]
        set bw11 [$sink2 set npkts_]
        set bw12 [$sink3 set lastPktTime_]
        set bw13 [$sink3 set npkts_]
        set bw14 [$sink4 set lastPktTime_]
        set bw15 [$sink4 set npkts_]
       
    set now [$ns now]
        # Record Bit Rate in Trace Files
        puts $f0 "$now [expr (($bw0+$holdrate1)*8)/(2*$time*1000000)]"
        puts $f1 "$now [expr (($bw1+$holdrate2)*8)/(2*$time*1000000)]"
        puts $f2 "$now [expr (($bw2+$holdrate3)*8)/(2*$time*1000000)]"
        puts $f3 "$now [expr (($bw3+$holdrate4)*8)/(2*$time*1000000)]"
       
        # Record Packet Loss Rate in File
        puts $f4 "$now [expr $bw4/$time]"
        puts $f5 "$now [expr $bw5/$time]"
        puts $f6 "$now [expr $bw6/$time]"
        puts $f7 "$now [expr $bw7/$time]"
 
        # Record Packet Delay in File
        if { $bw9 > $holdseq } {
                puts $f8 "$now [expr ($bw8 - $holdtime)/($bw9 - $holdseq)]"
        } else {
                puts $f8 "$now [expr ($bw9 - $holdseq)]"
        }

        if { $bw11 > $holdseq1 } {
                puts $f9 "$now [expr ($bw10 - $holdtime1)/($bw11 - $holdseq1)]"
        } else {
                puts $f9 "$now [expr ($bw11 - $holdseq1)]"
        }

        if { $bw13 > $holdseq2 } {
                puts $f10 "$now [expr ($bw12 - $holdtime2)/($bw13 - $holdseq2)]"
        } else {
                puts $f10 "$now [expr ($bw13 - $holdseq2)]"
        }
 
        if { $bw15 > $holdseq3 } {
                puts $f11 "$now [expr ($bw14 - $holdtime3)/($bw15 - $holdseq3)]"
        } else {
                puts $f11 "$now [expr ($bw15 - $holdseq3)]"
        }

        # Reset Variables
        $sink set bytes_ 0
        $sink2 set bytes_ 0
        $sink3 set bytes_ 0
        $sink4 set bytes_ 0

        $sink set nlost_ 0
        $sink2 set nlost_ 0
        $sink3 set nlost_ 0
        $sink4 set nlost_ 0

        set holdtime $bw8
        set holdseq $bw9
        set  holdrate1 $bw0
        set  holdrate2 $bw1
        set  holdrate3 $bw2
        set  holdrate4 $bw3

    $ns at [expr $now+$time] "record"   ;# 定時取樣的設定, 哈哈!
}
# set events for simulating!
$ns_ at 0.0 "record"
$ns_ at 1.4 "$app1 start"            
$ns_ at 10.0 "$app2 start"              
$ns_ at 20.0 "$app3 start"              
$ns_ at 30.0 "$app4 start"             

$ns_ at 80.0 "stop"
# Reset Nodes at time 80 sec
for {set i 0} {$i < $val(nn) } {incr i} {
    $ns_ at 80.0 "$node_($i) reset";
}

# Exit Simulatoion at Time 80.01 sec
$ns_ at 80.01 "puts /"NS EXITING.../" ; $ns_ halt"
proc stop {} {
        global ns_ tracefd f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11
        # Close Trace Files
        close $f0 
        close $f1
        close $f2
        close $f3
        close $f4 
        close $f5
        close $f6
        close $f7
        close $f8
        close $f9
        close $f10
        close $f11

        # Plot Recorded Statistics
        exec xgraph out02.tr out12.tr out22.tr out32.tr -geometry 800x400 &
        exec xgraph lost02.tr lost12.tr lost22.tr lost32.tr -geometry 800x400 &
        exec xgraph delay02.tr delay12.tr delay22.tr delay32.tr -geometry 800x400 &
        # Reset Trace File
        $ns_ flush-trace
        close $tracefd
        exit 0
}
puts "Starting Simulation..."
$ns_ run

相關推薦

無線網路吞吐量測量

# # # #=================================================================== # Define Node Configuration paramaters #======================================

NS吞吐量延遲等計算[轉載]

原文地址:http://blog.csdn.net/lqzixi/article/details/6044641 ------------------------------------- How to measure the throughput, packet dr

iOS計算網路測試,延遲,下載速度等引數iOS實現ping

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">

httping監控網路//狀態

web介面新增監控專案 型別: Zabbix客戶端 鍵值:如下 httping.status[failed,www.baidu.com,443,https] httping.status[max,www.baidu.com,443,https] httping.stat

android 下測試網路和延遲

昨天做網路延遲和丟包率,以前沒弄過,網上尋找也沒找到什麼有效的,弄了一下午搞定了,程式碼如下,希望對大家有幫助,寫的不好,還請大家批評指正 String lost = new String(); String delay = new String(); P

Linux下C獲取CPU使用率和記憶體和網路

在Linux中如果要監視一個程序的執行情況,如檢視它的CPU使用效率和記憶體使用情況,就需要從系統的 /proc目錄的讀取一些系統資訊。然後分析得到結果,proc檔案系統是一個偽檔案系統,它只存在記憶體當中,而不佔用外存空間。它以檔案系統的方式為訪問系統核心資料的操作提供介

linux 網路與傳輸頻寬關係測試

一、目的 在網際網路中,我們會向網路運營商申請指定額度的頻寬。實際傳輸時,由於網路QoS達不到要求,實際的傳輸頻寬可能達不到標

無線網路,使用MDK3把指定的使用者或者熱點踢到掉線(轉)

閱讀目錄   準備   驗證洪水攻擊 / Authentication Flood Attack   取消身份驗證攻擊 / Deauth攻擊   參考 回到頂部   準備   1:系統環境為ubuntu16.04,    2:需要mdk

計算機網路吞吐量的關聯理解

通過鏈路和交換機移動資料的方法有兩種:電路交換和分組交換 其中電路交換網路中,在端系統間通訊會話期間,是預留了資料傳輸所需的路徑資源。 所以對於吞吐量,時延的討論僅在分組交換網路中進行。 吞吐量: 考慮從主機A到B跨越計算機網路傳送檔案,則在任何時間瞬間的瞬時吞

WireShark 查看UDP碼流的

image 技術分享 sha png streams ima wireshark wire 分享圖片 1.用wireshark抓包之後,右擊,點decode as,轉化為RTP 2. 點show all streams 3.分析 WireShark 查看UDP碼流的丟包

zabbix監控IDC機房的shell指令碼

#!/bin/bash Count=0 Log=/tmp/pingloss.log function CHECK {         Count=0         for i in $IP_List;do                 FLAG=`/usr/local/

安卓在專案新增Android相容( v4v7 )

如何選擇相容包, 一、檢視SDK中是否有Support Library( v4、v7、、、) 注意該包是否在對應的SDK版本中!!! 二、沒有則進行下載Support Library 方法1:右擊專案→選擇Android Tools→Add Supp

TCP粘,拆及解決方法的原因及解決辦法

粘包、拆包發生原因 發生TCP粘包或拆包有很多原因,現列出常見的幾點,可能不全面,歡迎補充, 1、要傳送的資料大於TCP傳送緩衝區剩餘空間大小,將會發生拆包。 2、待發送資料大於MSS(最大報文長度),TCP在傳輸前將進行拆包。 3、要傳送的資料小於

TCP BBR算法的帶寬敏感性以及高下的優化

font 根據 div 我們 控制 行為 喇叭 存在 int bbr算法比較簡單也比較容易理解,所有關於它的優化也就同樣不復雜了。 請註意,任何優化都只針對特定場景的,根本不存在一種放任四海而皆準的算法。我們分析Google的測試報告時,比較容易被忽視的是其

Linux模擬網絡延遲

ack pan spa 進一步 netem 隨機 新版 物理 註意 一、工具介紹 1.netem netem 是 Linux 2.6 及以上內核版本提供的一個網絡模擬功能模塊。該功能模塊可以用來在性能良好的局域網中,模擬出復雜的互聯網傳輸性能,諸如低帶寬、傳輸延遲、丟包

TCP傳輸協議如何解決問題

  TCP在不可靠的網路上實現可靠的傳輸,必然會有丟包。TCP是一個“流”協議,一個詳細的包將會被TCP拆分為好幾個包上傳,也是將會把小的封裝成大的上傳,這就是說TCP粘包和拆包難題。 但是許多人有不同的理解。TCP協議本身確保傳輸的資料不會丟失完整性。如果在傳輸過

軟件安裝方法rpm介紹rpmyum

yum rpm安裝軟件包的三種方法window的exe文件就是二進制包,不能使用記事本文本打開。Linux下的ls命令文件也是二進制的。 rpm工具。類似Windows的exe源碼包 就是源代碼。需要編譯器編譯可執行文件Yum工具 操作的是rpm包。Yum工具是Python開發。自動安裝依賴的包。Yum就像

二十一安裝軟件的三種方法RPM介紹rpm工具用法yum工具用法yum搭建本地倉庫

rpm工具 yum工具 二十一、安裝軟件包的三種方法、RPM包介紹、rpm工具用法、yum工具用法、yum搭建本地倉庫一、安裝軟件包的三種方法rpm工具、yum工具、源碼包RPM工具:是以一種數據庫記錄的方式將需要的套件安裝到Linux主機的一套管理程序。就是說,你的Linux系統中有一個關於RPM的

安裝軟件的三種方法 rpm介紹rpm工具用法yum工具用法yum搭建本地倉庫安裝軟件

258866安裝軟件包的三種方法rpm包類似於windows的exe文件。rpm工具可以安裝rpm包,安裝路徑和文件名都是固定好的,不需要過多的設置。yum也可以安裝rpm包,比rpm工具好的一點是支持自動安裝依賴的包。源碼包主要是源代碼,需要誰用編譯器編譯成可執行的文件。·····rpm包介紹首先我們要把光

機器學習:評價分類結果(實現混淆矩陣精準召回

test set 目的 mod 二分 參數 nbsp return try 一、實例  1)構造極度偏差的數據 import numpy as np from sklearn import datasets digits = datasets.load_digits