上下行链路速率差距很大,若能动态调节上下行信道带宽,可优化用户体验,提高效率。
以下是利用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上下行链路丢包仿真相关推荐

  1. 台式机的无线网卡连接wifi,能连上但丢包严重,无法上网

    问题描述 系统:win10 cpu:amd r53600 网卡:AC 9260 3年前的电脑,用的不是很多.最近发现上网很慢,ping网关丢包严重.ping光猫网速还行.很奇怪. 解决方法 家中路由器 ...

  2. 检测网络是否稳定的计算机命令,怎么看电脑上网络丢包 查看网速有没稳定和网络是否延时方法...

    上网经常卡,玩网络游戏跳ping,延迟400ms很可能是你家的网络问题.那么,电脑上怎么看网络丢包?今天小编就来教大家如何查看自家的网络延时问题.对于一些网络游戏来说,对网速与稳定性要求很高,而一旦网 ...

  3. 怎么测试linux丢包率,linux上测试丢包率的工具iperf介绍

    今天要测试一下linux上udp的丢包率,查了一下,有个iperf的可以做这个,分别在发送端和接收端安装命令,然后运行一下就行了, 首先在服务端设置 iperf -p 80 -s -u -i 1 参数 ...

  4. 云网络丢包故障定位全景指南

    作者简介:冯荣,腾讯云网络高级工程师,腾讯云网络核心开发人员. 万字长文  建议收藏 引言 本期分享一个比较常见的⽹络问题--丢包.例如我们去ping⼀个⽹站,如果能ping通,且⽹站返回信息全⾯,则 ...

  5. 深度好文:云网络丢包故障定位,看这一篇就够了~

    深度好文:云网络丢包故障定位,看这一篇就够了~ https://mp.weixin.qq.com/s/-Q1AkxUr9xzGKwUMV-FQhQ Alex 高效运维 今天 来源:本文经授权转自公众号 ...

  6. 【linux】net-speeder减少由于网络距离过远导致的丢包问题

    介绍 当网络距离过远时,可能会由于中间节点性能太差或延迟过高导致数据丢包的问题.虽然tcp有重传的机制,但是同时也会增大网络延迟.net-speeder采用多倍发包,同时发送N个数据到出来,只要其中有 ...

  7. Linux丢包问题排查思路

    Linux丢包问题排查思路 判断问题与网络丢包有关 通过抓tcpdump,通过wireshark提示查看数据包状态.比如客户端重传多次失败,服务端提示丢包等错误,均是可能由于丢包导致的异常. 丢包可能 ...

  8. ping命令一直测试网络丢包原因及处理解决方法

    所谓的网络丢包是我们在使用ping对目站进行询问时,数据包由于各种原因在信道中丢失的现象.ping 使用了ICMP 回送请求与回送回答报文.ICMP 回送请求报文是主机或路由器向一个特定的目的主机发出 ...

  9. php防丢包,记一次有惊无险的丢包调试经历

    某个项目把服务器从 CentOS 操作系统从 5 升级到了 7(3.10.0-693),一切都很顺利,直到我在服务器上闲逛的时候,无意间发现了一个「大问题」:网卡 eth0 在 RX 上存在丢包(dr ...

最新文章

  1. php矢量瓦片,矢量瓦片相关计算函数
  2. 【转】3.1SharePoint服务器端对象模型 之 访问文件和文件夹(Part 1)
  3. 根据 设备名(br0/eth0/em0)称获取 当前机器的IP地址与子网掩码信息
  4. 南充一中计算机机房被盗,四川省CCF CSP-JS第一轮认证考试在南充一中成功举行...
  5. IDEA之Initialization failed for ‘http://start.spring.io‘ Please check URL, network and proxy settings
  6. python中用于循环结构的关键字_详解Python的循环结构知识点
  7. OpenGL+VS2013环境配置
  8. 言情小说通用情节[转]
  9. 【Docker】MySQL 主从配置(一主一从)
  10. 阿里巴巴开发手册介绍
  11. UVA - 12235 Help Bubu 概率dp 状态压缩 记忆化搜索
  12. 再次推荐下这本书 —— DDIA
  13. antd 时间选择器,设置显示为中文
  14. 微信邮箱是什么?微信邮箱怎么注册申请,微信邮箱怎么登陆?
  15. c语言编译 创建卡号信息表,C语言超市会员信息管理系统源程序
  16. linux firefox体验,Firefox插件 让你在桌面浏览器体验Firefox OS(附安装教程)
  17. python模块:Sockets阻塞和非阻塞测试
  18. 使用Python统计股票高开后的走势
  19. oracle gho系统吗,系统镜像GHO、WIM、ESD几种格式的区别
  20. python Deformation Transfer for Triangle Meshes

热门文章

  1. 刚入门者必看(如何在c++里定义字符串数组)
  2. ipadpro分屏怎么操作_Amazing~你知道iPad Pro +优越者多功能TypeC扩展坞=?
  3. 解决Linux环境下Jupyter Lab平台使用python的Matplotlib函数库绘图时无法识别中文字体问题——永久识别方法
  4. Android SDK的安装配置
  5. python3 文件读取和写入中文
  6. Linux内存分配--实现FF、BF、WF分配算法
  7. Oracle创建视图时显示没有权限
  8. 使用Python获取ADS-B数据,并显示飞机航迹动态
  9. Nifty Gateway与区块链技术:探索数字艺术的革命
  10. html设置密码,设置密码.html