NS-3上下行鏈路丟包模擬
上下行鏈路速率差距很大,若能動態調節上下行通道頻寬,可優化使用者體驗,提高效率。
以下是利用NS-3模擬上下行鏈路程式碼:
#include <iostream> #include <fstream> #include <string> #include <cassert> #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/internet-module.h" #include "ns3/point-to-point-module.h" #include "ns3/applications-module.h" #include "ns3/ipv4-global-routing-helper.h" #include "ns3/random-variable-stream.h" #include "ns3/random-variable-stream-helper.h" using namespace ns3; using namespace std; NS_LOG_COMPONENT_DEFINE ("uplink-downlink-Example4"); static void RxDrop (Ptr<const Packet> p) //丟包 回撥函式 { NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ()); } int main (int argc, char *argv[]) { Time::SetResolution (Time::NS);//設定時間單位為納秒 LogComponentEnable ("uplink-downlink-Example4", LOG_LEVEL_INFO); LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_INFO); // LogComponentEnable ("TcpSocketImpl", LOG_LEVEL_ALL); LogComponentEnable ("PacketSink", LOG_LEVEL_INFO); //Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (1024)); //Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("50Mb/s")); CommandLine cmd; cmd.Parse (argc,argv); NodeContainer nodes; nodes.Create (2);//建立2個節點 PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("100000Mbps")); pointToPoint.SetChannelAttribute ("Delay", StringValue ("0.002ms")); NetDeviceContainer devices; devices = pointToPoint.Install (nodes); InternetStackHelper stack; stack.Install (nodes); ////////////設定丟包率 Ptr<UniformRandomVariable> x =CreateObject<UniformRandomVariable>(); x->SetAttribute ("Min",DoubleValue(0)); x->SetAttribute ("Max",DoubleValue(1)); // Ptr<RateErrorModel> em = CreateObjectWithAttributes<RateErrorModel> ( "RanVar", StringValue ("ns3::ConstantRandomVariable[Constant=0.000002583]"), "ErrorRate", DoubleValue (0.00001)); Ptr<RateErrorModel> em_1 = CreateObjectWithAttributes<RateErrorModel> ( "RanVar", StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),"ErrorRate", DoubleValue (0.0001)); devices.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em_1)); devices.Get(0)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop)); ///////////////////////////////////////////////////////////////////////////////////////////// Ptr<RateErrorModel> em_2 = CreateObjectWithAttributes<RateErrorModel> ( "RanVar", StringValue("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),"ErrorRate", DoubleValue (0.0001)); devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em_2)); devices.Get(1)->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback (&RxDrop)); ////////////////////////////////////// Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); uint16_t port_1 = 50000; ApplicationContainer sinkApp_1; Address sinkLocalAddress_1 (InetSocketAddress (Ipv4Address::GetAny (), port_1)); PacketSinkHelper sinkHelper_1 ("ns3::TcpSocketFactory", sinkLocalAddress_1); sinkApp_1.Add(sinkHelper_1.Install(nodes.Get(1))); // Packet sink 安裝在第二個節點上 sinkApp_1.Start (Seconds (0.0)); sinkApp_1.Stop (Seconds (30.0)); OnOffHelper clientHelper_1 ("ns3::TcpSocketFactory", Address ()); //clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ExponentialRandomVariable[Mean=0.01|Variance=0.5|Bound=0.0]")); clientHelper_1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0002583]")); ///注意是豎線分隔 各個不同的引數 clientHelper_1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0001583]")); clientHelper_1.SetAttribute ("PacketSize", UintegerValue (1024)); clientHelper_1.SetAttribute ("DataRate", StringValue ("1Mbps")); ApplicationContainer clientApps_1; //節點1>節點2 AddressValue remoteAddress_1 (InetSocketAddress (interfaces.GetAddress (1), port_1)); clientHelper_1.SetAttribute("Remote",remoteAddress_1); clientApps_1.Add(clientHelper_1.Install(nodes.Get(0))); clientApps_1.Start(Seconds(1.0)); clientApps_1.Stop (Seconds(10.0)); /////////////////////////////////////downlink //////// uint16_t port_2 = 50001; ApplicationContainer sinkApp_2; Address sinkLocalAddress_2 (InetSocketAddress (Ipv4Address::GetAny (), port_2)); PacketSinkHelper sinkHelper_2 ("ns3::TcpSocketFactory", sinkLocalAddress_2); sinkApp_2.Add(sinkHelper_2.Install(nodes.Get(0))); // Packet sink 安裝在第二個節點上 sinkApp_2.Start (Seconds (0.0)); sinkApp_2.Stop (Seconds (30.0)); OnOffHelper clientHelper_2 ("ns3::TcpSocketFactory", Address ()); //clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ExponentialRandomVariable[Mean=0.01|Variance=0.5|Bound=0.0]")); clientHelper_2.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0002583]")); ///注意是豎線分隔 各個不同的引數 clientHelper_2.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=0.0001583]")); clientHelper_2.SetAttribute ("PacketSize", UintegerValue (1024)); clientHelper_2.SetAttribute ("DataRate", StringValue ("100Mbps")); ApplicationContainer clientApps_2; //節點1>節點2 AddressValue remoteAddress_2 (InetSocketAddress (interfaces.GetAddress (0), port_2)); clientHelper_2.SetAttribute("Remote",remoteAddress_2); clientApps_2.Add(clientHelper_2.Install(nodes.Get(1))); clientApps_2.Start(Seconds(1.0)); clientApps_2.Stop (Seconds(10.0)); Ipv4GlobalRoutingHelper::PopulateRoutingTables (); //嗅探,記錄所有節點相關的資料包 pointToPoint.EnablePcapAll("uplink-downlink-Tcp4"); Simulator::Run (); Simulator::Destroy (); return 0; }
利用wireshark解析上下行鏈路的吞吐率:
其中
tcp.port==50000 是上行鏈路的接受埠的吞吐率
tcp.port==50001 是下行鏈路的接受埠的吞吐率
相關推薦
NS-3上下行鏈路丟包模擬
上下行鏈路速率差距很大,若能動態調節上下行通道頻寬,可優化使用者體驗,提高效率。 以下是利用NS-3模擬上下行鏈路程式碼: #include <iostream> #include <fstream> #include <
BPSK-QPSK調製下PNC下行鏈路LDPC譯碼
%%%%-----此段程式碼完成PNC下行鏈路LDPC譯碼,中繼端資料假設是理想接收無差錯---%%%% clc clear code_length=24; %碼長 code_rate=1/2; %位元速率 max_iter=20; %譯碼最大迭代次數 SNR=
windows下網路丟包模擬軟體(Network Emulator for Windows Toolkit)
最近公司有一個直播的測試專案,需要模擬各種網路環境下的直播狀態,最後找到一款這樣的軟體(如果有遇到更好的軟體,望和網友多多交流) 介紹一款windows下的網路模擬器,可以模擬各種丟包或延遲的網路(Network Emulator for Windows Toolkit) 下載地址:https://blo
【疑】checkpoint防火墻雙鏈路切換導致丟包問題
.com 技術分享 通過 check 配置 分享 png nbsp int 拓撲: 外線聯通、電信各200M,通過邊界交換機(純二層,用於分線),分別接到主、備防火墻。 具體配置如下: 【疑】checkpoint防火墻雙鏈路切換導致丟包問題
距離矢量路由協議以及鏈路狀態路由協議(2018年1月3日 09:09:15)
靈活 矢量路由協議 園區 訪問 邊界 建議 stat 幫助 post 距離矢量路由協議以及鏈路狀態路由協議 -------------------- 靜態路由 通過(NQA 思科叫SLA) -----服務級別協定 建議使用靜態的情況:園區網邊界 默認路由(缺省路由) 靜
OSPF-4 鏈路狀態數據的結構和五種包
ccna ccnp ccie hcie 思科 一、鏈路狀態數據的結構 每個LSA條目都有老化定時器(aging timer),它存儲在鏈路狀態年齡(age)字段中。在默認情況下,30分鐘(在年齡字段中,以秒為單位)後,最初發送該條目的路由器發送一個鏈路狀態更新(LSU),其中包含序列號更
鏈路內和鏈路外的數據包發送:單播、組播、任播
存在 sse ast 比特 inf 正常 ip組播 nan root 翻譯自:https://info.menandmice.com/blog/bid/103274/On-link-vs-Off-Link-Packet-Delivery-Unicast-Multicast-
習題 13.2 從鍵盤輸入一批數值,要求保留3位小數,在輸出時上下行小數點對齊。
C++程式設計(第三版) 譚浩強 習題13.2 個人設計 習題 13.2 從鍵盤輸入一批數值,要求保留3位小數,在輸出時上下行小數點對齊。 程式碼塊: #include <iostream> #include <iomanip> using names
福利|人人都能讀懂的極簡掌上區塊鏈圖書,免費送還包郵,手慢無
編輯 | kou 從江湖故事到社會共識,區塊鏈是一個關乎信任的偉大技術實驗! 福利!本文節選自《極簡區塊鏈》,文末免費送書(+速查小手冊)5本。 看正文之前,先聽聽網易有道CEO周楓是如何評價這本書
雲上資料庫“全鏈路安全”實踐:保護企業核心資產
資料庫所儲存的是企業最為核心的資產,所以對於企業而言,必須要將資料庫的安全做到位。那麼,如何保證雲上資料庫的安全呢?在本文中,阿里雲資料庫高階產品專家崔京(花名:乙休)就為大家帶來了雲資料庫的“全鏈路安全”。 在大家心中,資料庫安全到底指什麼呢?其實資料庫安全可以分為幾個方面理解,首先是資料連續可用,
一次存儲鏈路抖動因I/O timeout不同在AIX和HPUX上的不同表現(轉)
有意思 建議 超時 values 最終 tar output 沈澱 possible 去年一個故障案例經過時間的沈澱問題沒在發生今天有時間簡單的總結一下,當時正時午睡時分,突然告警4庫8個實例同時不可用,這麽大面積的故障多數是有共性的關連,當時查看數據庫DB ALERT日誌
一次儲存鏈路抖動因I/O timeout不同在AIX和HPUX上的不同表現(轉)
去年一個故障案例經過時間的沉澱問題沒在發生今天有時間簡單的總結一下,當時正時午睡時分,突然告警4庫8個例項同時不可用,這麼大面積的故障多數是有共性的關連,當時檢視資料庫DB ALERT日誌都是I/O錯誤寫失敗,後確認8個例項都是使用了儲存層的同步容災技術,且儲存為同一品牌日立。 2017-01-22 13:
史上最簡單的SpringCloud教程 | 第九篇: 服務鏈路追蹤(Spring Cloud Sleuth)(Finchley版本)
這篇文章主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 一、簡介 Add sleuth to the classpath of a Spring Boot application (see below for Maven
藍芽學習(四)-- 低功耗藍芽(BLE)鏈路層資料包
octet : 八位位元組 鏈路層定義了兩個裝置如何利用無線電傳輸資訊。它包含了報文、廣播資料通道的詳細定義,也規定了發現其他裝置的流程、廣播的資料、連線的建立、連線的管理以及連線中的資料傳輸。 下圖是報文的基本結構,適用於所有的報文,無論其用途是什麼。報文一開始是一小段訓練
區塊鏈焦慮症:用賣肉包的理論分析你是不是一定要上區塊鏈的車
說起區塊鏈的好處,去中心化、資料不可篡改、集體維護、資訊公開透明等一系列字眼都會輕易地從你腦海中跳出來。 2016年是“區塊鏈元年”,區塊鏈技術本身得到了人們的關注。眾多傳統金融機構以及技術開發公司開始了對區塊鏈技術的研究和討論。 經過短短的一年,在區塊鏈的播種得到了收穫。大量的專案開始落地
Dubbox 鏈路追蹤(基於Brave+Zipkin的簡單實現)上
很多時候,我們都能體會到分散式架構的話好處,其實一個系統不大,做分散式的成本是很高的,系統變得鬆耦合,這樣做的好處不言而喻,說說壞處吧,A系統遠端呼叫B系統,B系統又依賴C,D系統,當線上某個介面報錯,或者超時的時候,亦或者是業務問題的時候,定位一個問題是麻煩的,因為日記不
NS中吞吐量,丟包率,端到端延遲等計算[轉載]
原文地址:http://blog.csdn.net/lqzixi/article/details/6044641 ------------------------------------- How to measure the throughput, packet dr
SOCKET客戶端與服務端長時間通訊後,會連線不上服務端的問題,以及server端UDP丟包的問題
人生第一篇部落格,希望能以一個好的開始,持之以恆下去! 這兩天在做有關負載均衡的一個專案,期間在除錯時遇到了一個問題:客戶端與服務端依靠socket通訊,但是長時間通訊後,會發生客戶端連線不上服務端的狀況。而後查詢了一些資料後,終於搞清楚問題的緣由了,在此和大家分享一下!
NS-3中計算packet延遲(每一個包的延遲)
參考 http://blog.sina.com.cn/s/articlelist_1562399961_14_1.html 在NS-3中計算包的延遲:=包接收時間-包傳送時間; 具體在adhoc網路
史上最簡單的SpringCloud教程 | 第九篇: 服務鏈路追蹤(Spring Cloud Sleuth)
這篇文章主要講述服務追蹤元件zipkin,Spring Cloud Sleuth集成了zipkin元件。 一、簡介 Add sleuth to the classpath of a Spring Boot application (see below fo