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
l(app,"abcdef");
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
版权声明:本文标题:NS3 实时仿真设置(first样例代码) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1710956467a292193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论