官方文档:MyApp

可以在下面的几个例子找到:

examples/tutorial/fifth.cc

examples/tutorial/seventh.cc

examples/tutorial/sixth.cc

SetUp函数


class MyApp : public Application
{
public: MyApp ();
virtual ~MyApp(); void Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate); private:
virtual void StartApplication (void);
virtual void StopApplication (void); void ScheduleTx (void);
void SendPacket (void); Ptr<Socket> m_socket;
Address m_peer;
uint32_t m_packetSize;
uint32_t m_nPackets;
DataRate m_dataRate;
EventId m_sendEvent;
bool m_running;
uint32_t m_packetsSent;
}; MyApp::MyApp ()
: m_socket (0),
m_peer (),
m_packetSize (0),
m_nPackets (0),
m_dataRate (0),
m_sendEvent (),
m_running (false),
m_packetsSent (0)
{
} MyApp::~MyApp()
{
m_socket = 0;
} void
MyApp::Setup (Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, DataRate dataRate)
{
m_socket = socket;
m_peer = address;
m_packetSize = packetSize;
m_nPackets = nPackets;
m_dataRate = dataRate;
} void
MyApp::StartApplication (void)
{
m_running = true;
m_packetsSent = 0;
m_socket->Bind ();
m_socket->Connect (m_peer);
SendPacket ();
} void
MyApp::StopApplication (void)
{
m_running = false; if (m_sendEvent.IsRunning ())
{
Simulator::Cancel (m_sendEvent);
} if (m_socket)
{
m_socket->Close ();
}
} void
MyApp::SendPacket (void)
{
Ptr<Packet> packet = Create<Packet> (m_packetSize);
m_socket->Send (packet); if (++m_packetsSent < m_nPackets)
{
ScheduleTx ();
}
} void
MyApp::ScheduleTx (void)
{
if (m_running)
{
Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.GetBitRate ())));
m_sendEvent = Simulator::Schedule (tNext, &MyApp::SendPacket, this);
}
} static void
CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
{
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
} static void
RxDrop (Ptr<const Packet> p)
{
NS_LOG_UNCOND ("RxDrop at " << Simulator::Now ().GetSeconds ());
}

NS3 MyApp Class Reference的更多相关文章

  1. WPF笔记(1.1 WPF基础)——Hello,WPF!

    原文:WPF笔记(1.1 WPF基础)--Hello,WPF! Example 1-1. Minimal C# WPF application// MyApp.csusing System;using ...

  2. Springfox Reference Documentation

    1. Introduction The Springfox suite of java libraries are all about automating the generation of mac ...

  3. Xcode Build Setting Reference

    https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/ ...

  4. Configuration Reference In Vue CLI 3.0

    Configuration Reference This project is sponsored by  #Global CLI Config Some global configurations ...

  5. NS3 fifth.cc 拥塞窗口实例

    fifth.cc /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * This progr ...

  6. NS3 Ptr<Rocket> 与 TcpRocket 的一个小问题

    前因:ns3网络仿真 实验进行到很关键的一步,我尝试进行了代码的编写(还没有添加Traceback的函数),如下: #include "ns3/core-module.h" #in ...

  7. Spring Boot Reference Guide

    Spring Boot Reference Guide Authors Phillip Webb, Dave Syer, Josh Long, Stéphane Nicoll, Rob Winch,  ...

  8. ns3 802.11b PHY model

    I use the ubuntu and do not install the chinse input. The Code: c file requires gnu gsl library, it ...

  9. ASP.NET Core: You must add a reference to assembly mscorlib, version=4.0.0.0

    ASP.NET Core 引用外部程序包的时候,有时会出现下面的错误: The type 'Object' is defined in an assembly that is not referenc ...

随机推荐

  1. 用Delphi写一个UTF8编码格式的文本文件

    ... var f: TextFile; begin AssignFile(f, 'test.txt'); Rewrite(f); write(f, #$EF+#$BB+#$BF); // UTF-8 ...

  2. Tomcat项目部署的三种方法

    第一种方法如下:直接把我们的项目文件夹放到tomcat里面,在这里我自己做的是一个测试项目oa,如图 启动tomcat,打开浏览器,输入localhost/oa  即可打开你的文件,注意 :访问的时候 ...

  3. [py]GIL(全局解释器锁):多线程模式

    在多线程 时同一时刻只允许一个线程来访问CPU,直到解释器遇到I/O操作或者操作次数达到一定数目时才会释放GIL 参考 Python虽然不能利用多线程实现多核任务,但可以通过多进程实现多核任务.多个P ...

  4. Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of

    eclipse在build maven项目的时候报错, 原来是Windows------->preference----->maven----------->usesettings配 ...

  5. numpy 中clip函数的使用

    其中a是一个数组,后面两个参数分别表示最小和最大值 也就是说clip这个函数将将数组中的元素限制在a_min, a_max之间,大于a_max的就使得它等于 a_max,小于a_min,的就使得它等于 ...

  6. Ajax学习整理笔记

    AJAX技术的出现使得javascript技术大火.不懂AJAX的同学百度一下,了解AJAX能做什么就可以了. 代码: <!DOCTYPE html> <html> <h ...

  7. acrobat pro 无法编辑个别文本

    在修改pdf文档时出现个别文字选取不上,无法修改,如图中4-2626没有选中 解决方法如图 此后可以直接修改文本了

  8. LeetCode-MinimumDepthOfBinaryTree

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

  9. wprintf或_tprintf不显示中文和乱码问题

    1.由于中文问题,宽字节编译时会遇到一些不显示或显示乱码问题 如下列代码:  分别是WIN API写入和读取文件,测试_tprintf就会不显示 #include "stdafx.h&quo ...

  10. Chrome 性能监测

    前端性能优化一直是前端工作中必不可少的一部分,但是我们如何知道哪些部分的性能有优化的空间呢?此时,Chrome 性能监测就派上用场了. 正所谓:知己知彼,百战百胜,只有确定了性能瓶颈,才能有条不紊地进 ...