admin管理员组

文章数量:1568307

2024年3月21日发(作者:)

以NS3样例代码为例,添加红色字体部分即可实现实时仿真。

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */

/*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License version 2 as

* published by the Free Software Foundation;

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307

*/

#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"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int

main (int argc, char *argv[])

{

LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);

LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

// 绑定实时模拟方式

GlobalValue::Bind ("SimulatorImplementationType",

("ns3::RealtimeSimulatorImpl"));

NodeContainer nodes;

(2);

PointToPointHelper pointToPoint;

USA

StringValue

iceAttribute ("DataRate", StringValue ("5Mbps"));

nnelAttribute ("Delay", StringValue ("2ms"));

NetDeviceContainer devices;

devices = l (nodes);

InternetStackHelper stack;

l (nodes);

Ipv4AddressHelper address;

e ("192.168.62.0", "255.255.255.0");

Ipv4InterfaceContainer interfaces = (devices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = l ( (1));

(Seconds (1.0));

(Seconds (10.0));

UdpEchoClientHelper echoClient (ress (1), 9);

ribute ("MaxPackets", UintegerValue (3));

ribute ("Interval", TimeValue (Seconds (3.0))); // 3秒钟间隔

ribute ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps = l ( (0));

(Seconds (1.5));

(Seconds (10.0));

Ptr app = (0);

l(app,"abcdef");

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

本文标签: 代码样例部分红色字体