news 2026/1/11 15:36:05

NS3仿真——fifth

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
NS3仿真——fifth

fifth引入了tcp的newreno模型,以及信道错误概率,对于tcp拥塞控制的研究,可以后期在此基础上进行更改

1.文件头注释

/* GPL许可证声明 */ #include "tutorial-app.h" // 关键:自定义应用头文件 #include "ns3/applications-module.h" // 应用层模块 #include "ns3/core-module.h" // 核心模块 #include "ns3/internet-module.h" // 网络层模块 #include "ns3/network-module.h" // 网络模块 #include "ns3/point-to-point-module.h" // 点对点链路模块 #include <fstream>

为什么需要自定义应用:

问题1:OnOff应用的socket在启动时才创建,无法在配置时连接跟踪点 问题2:即使能在启动后连接,socket不是public的,无法访问 解决方案:创建自定义的简单应用

2.TCP参数配置

设置拥塞策略为tcpnewreno,类似的还有cubic等;

初始拥塞窗口以及窗口恢复机制同样可以设置

Config::SetDefault("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpNewReno")); Config::SetDefault("ns3::TcpSocket::InitialCwnd", UintegerValue(1)); // 初始拥塞窗口=1包 Config::SetDefault("ns3::TcpL4Protocol::RecoveryType", TypeIdValue(TypeId::LookupByName("ns3::TcpClassicRecovery")));

3、网络建立过程

步骤1:创建节点和链路

NodeContainer nodes; nodes.Create(2); // 创建2个节点 PointToPointHelper pointToPoint; pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")); pointToPoint.SetChannelAttribute("Delay", StringValue("2ms")); NetDeviceContainer devices; devices = pointToPoint.Install(nodes);

步骤2:配置错误模型

Ptr<RateErrorModel> em = CreateObject<RateErrorModel>(); em->SetAttribute("ErrorRate", DoubleValue(0.00001)); // 0.001%错误率 devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em));

步骤3:安装协议栈和IP地址

InternetStackHelper stack; stack.Install(nodes); // 安装TCP/IP协议栈 Ipv4AddressHelper address; address.SetBase("10.1.1.0", "255.255.255.252"); // 30位掩码 Ipv4InterfaceContainer interfaces = address.Assign(devices);

步骤4:创建接收端应用

uint16_t sinkPort = 8080; Address sinkAddress(InetSocketAddress(interfaces.GetAddress(1), sinkPort)); PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", InetSocketAddress(Ipv4Address::GetAny(), sinkPort)); ApplicationContainer sinkApps = packetSinkHelper.Install(nodes.Get(1)); sinkApps.Start(Seconds(0.)); sinkApps.Stop(Seconds(20.));

步骤5:关键部分 - 创建socket并连接跟踪点

Ptr<Socket> ns3TcpSocket = Socket::CreateSocket(nodes.Get(0), TcpSocketFactory::GetTypeId()); ns3TcpSocket->TraceConnectWithoutContext("CongestionWindow", MakeCallback(&CwndChange));

步骤6:创建自定义发送应用

Ptr<TutorialApp> app = CreateObject<TutorialApp>(); app->Setup(ns3TcpSocket, sinkAddress, 1040, 1000, DataRate("1Mbps")); nodes.Get(0)->AddApplication(app); app->SetStartTime(Seconds(1.)); app->SetStopTime(Seconds(20.));

步骤7:连接丢包跟踪点

devices.Get(1)->TraceConnectWithoutContext("PhyRxDrop", MakeCallback(&RxDrop));

4、回调函数分析

1.拥塞窗口变化回调

static void CwndChange(uint32_t oldCwnd, uint32_t newCwnd) { NS_LOG_UNCOND(Simulator::Now().GetSeconds() << "\t" << newCwnd); }

2.接收丢包回调

static void RxDrop(Ptr<const Packet> p) { NS_LOG_UNCOND("RxDrop at " << Simulator::Now().GetSeconds()); }

部分运行截图

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2025/12/13 18:50:32

Flutter国际化终极指南:Easy Localization完整教程

Flutter国际化终极指南&#xff1a;Easy Localization完整教程 【免费下载链接】easy_localization Easy and Fast internationalizing your Flutter Apps 项目地址: https://gitcode.com/gh_mirrors/ea/easy_localization 想象一下&#xff0c;你的Flutter应用能在全球…

作者头像 李华
网站建设 2025/12/13 18:50:02

光刻胶增感剂用正丁胺

正丁胺分子结构图引言&#xff1a;正丁胺&#xff08;n-Butylamine&#xff09;在光刻胶中作为光增感剂&#xff08;Photosensitizer&#xff09;或助剂&#xff0c;主要用于提升光刻胶的感光度、分辨率和成像质量。能有效吸收特定波长紫外线&#xff0c;加速光固化过程&#x…

作者头像 李华
网站建设 2025/12/13 18:45:10

3步搭建Flink监控系统:从零到一的Prometheus实战指南

还在为Flink集群运行状态"两眼一抹黑"而烦恼吗&#xff1f;&#x1f3af; 今天我们就来彻底解决这个运维痛点&#xff0c;用最简单的方式搭建完整的Flink监控体系。Apache Flink作为业界领先的流处理框架&#xff0c;其监控能力往往被低估&#xff0c;其实只需几个配…

作者头像 李华
网站建设 2025/12/18 3:56:21

终极指南:快速掌握Adams机械动力学仿真全流程

终极指南&#xff1a;快速掌握Adams机械动力学仿真全流程 【免费下载链接】Adams入门详解与实例李增刚.pdf分享 《Adams入门详解与实例》是由李增刚编写的&#xff0c;旨在为希望掌握Adams软件使用的读者提供一套系统的学习资料。本书深入浅出&#xff0c;不仅涵盖了Adams的基础…

作者头像 李华
网站建设 2026/1/6 17:30:40

ProComponents 企业级组件库终极指南:5分钟构建专业后台系统

ProComponents 企业级组件库终极指南&#xff1a;5分钟构建专业后台系统 【免费下载链接】pro-components &#x1f3c6; Use Ant Design like a Pro! 项目地址: https://gitcode.com/gh_mirrors/pr/pro-components 你是否曾经在开发企业级管理系统时&#xff0c;面对复…

作者头像 李华