1 举例说明

(1)其中注意点:
Config path要找对:

oss<<"/NodeList/"<<wifiStaNodes.Get(nWifi-1)->GetId()<<"/$ns3::MobilityModel/CourseChange";

(2)如何确定Trace Sources
官网链接查看:https://www.nsnam.org/doxygen/_trace_source_list.html

(3)如何确定Trace Sink

  • A,在已有程序中找参照的,进行修改,例如mythird中的,可以参考mixed-wired-wireless.cc
  • B,其他方法:
    ① 先把返回值设为void
    ②参数列表类型就是Trace Sourse的变量类型,根据(2)中提供的方法,找到对应的Trace Sourse,查看其类型,即可。
/* -*- 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  USA*/#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"// Default Network Topology
//
//   Wifi 10.1.3.0
//                 AP
//  *    *    *    *
//  |    |    |    |    10.1.1.0
// n5   n6   n7   n0 -------------- n1   n2   n3   n4
//                   point-to-point  |    |    |    |
//                                   ================
//                                     LAN 10.1.2.0using namespace ns3;using namespace std;NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");void CourseChange(string context, Ptr<const MobilityModel> model)
{Vector position = model->GetPosition();NS_LOG_UNCOND(context<<" x = "<<position.x<<" y = "<< position.y);}int
main (int argc, char *argv[])
{bool verbose = true;uint32_t nCsma = 3;uint32_t nWifi = 3;bool tracing = false;CommandLine cmd;cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);cmd.AddValue ("tracing", "Enable pcap tracing", tracing);cmd.Parse (argc,argv);// The underlying restriction of 18 is due to the grid position// allocator's configuration; the grid layout will exceed the// bounding box if more than 18 nodes are provided.if (nWifi > 18){std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the bounding box" << std::endl;return 1;}if (verbose){LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);}NodeContainer p2pNodes;p2pNodes.Create (2);PointToPointHelper pointToPoint;pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));NetDeviceContainer p2pDevices;p2pDevices = pointToPoint.Install (p2pNodes);NodeContainer csmaNodes;csmaNodes.Add (p2pNodes.Get (1));csmaNodes.Create (nCsma);CsmaHelper csma;csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));NetDeviceContainer csmaDevices;csmaDevices = csma.Install (csmaNodes);NodeContainer wifiStaNodes;wifiStaNodes.Create (nWifi);NodeContainer wifiApNode = p2pNodes.Get (0);YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();phy.SetChannel (channel.Create ());WifiHelper wifi;wifi.SetRemoteStationManager ("ns3::AarfWifiManager");WifiMacHelper mac;Ssid ssid = Ssid ("ns-3-ssid");mac.SetType ("ns3::StaWifiMac","Ssid", SsidValue (ssid),"ActiveProbing", BooleanValue (false));NetDeviceContainer staDevices;staDevices = wifi.Install (phy, mac, wifiStaNodes);mac.SetType ("ns3::ApWifiMac","Ssid", SsidValue (ssid));NetDeviceContainer apDevices;apDevices = wifi.Install (phy, mac, wifiApNode);MobilityHelper mobility;mobility.SetPositionAllocator ("ns3::GridPositionAllocator","MinX", DoubleValue (0.0),"MinY", DoubleValue (0.0),"DeltaX", DoubleValue (5.0),"DeltaY", DoubleValue (10.0),"GridWidth", UintegerValue (3),"LayoutType", StringValue ("RowFirst"));mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel","Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));mobility.Install (wifiStaNodes);mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");mobility.Install (wifiApNode);InternetStackHelper stack;stack.Install (csmaNodes);stack.Install (wifiApNode);stack.Install (wifiStaNodes);Ipv4AddressHelper address;address.SetBase ("10.1.1.0", "255.255.255.0");Ipv4InterfaceContainer p2pInterfaces;p2pInterfaces = address.Assign (p2pDevices);address.SetBase ("10.1.2.0", "255.255.255.0");Ipv4InterfaceContainer csmaInterfaces;csmaInterfaces = address.Assign (csmaDevices);address.SetBase ("10.1.3.0", "255.255.255.0");address.Assign (staDevices);address.Assign (apDevices);UdpEchoServerHelper echoServer (9);ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));serverApps.Start (Seconds (1.0));serverApps.Stop (Seconds (10.0));UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);echoClient.SetAttribute ("MaxPackets", UintegerValue (1));echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));echoClient.SetAttribute ("PacketSize", UintegerValue (1024));ApplicationContainer clientApps = echoClient.Install (wifiStaNodes.Get (nWifi - 1));clientApps.Start (Seconds (2.0));clientApps.Stop (Seconds (10.0));Ipv4GlobalRoutingHelper::PopulateRoutingTables ();Simulator::Stop (Seconds (10.0));if (tracing == true){pointToPoint.EnablePcapAll ("third");phy.EnablePcap ("third", apDevices.Get (0));csma.EnablePcap ("third", csmaDevices.Get (0), true);}ostringstream oss;oss<<"/NodeList/"<<wifiStaNodes.Get(nWifi-1)->GetId()<<"/$ns3::MobilityModel/CourseChange";NS_LOG_UNCOND(oss.str());Config::Connect(oss.str(),MakeCallback(&CourseChange));Simulator::Run ();Simulator::Destroy ();return 0;
}

ns-3学习手记15_ns3中使用Trace Sourse 和Trace Sink输出数据相关推荐

  1. R语言学习手记 (1)

    R语言学习手记 (1) 经管的会计和财管都会学数据统计与分析R语言这门课,加上我也有点兴趣,就提前选了这门课,以下的笔记由老师上课的PPT.<R语言编程艺术>和<R语言数据科学> ...

  2. [王晓刚]深度学习在图像识别中的研究进展与展望(转发)

    [王晓刚]深度学习在图像识别中的研究进展与展望(转发) (2015-06-04 08:27:56) 转载▼     深度学习是近十年来人工智能领域取得的最重要的突破之一.它在语音识别.自然语言处理.计 ...

  3. 王晓刚:深度学习在图像识别中的研究进展与展望

    深度学习是近十年来人工智能领域取得的最重要的突破之一.它在语音识别.自然语言处理.计算机视觉.图像与视频分析.多媒体等诸多领域都取得了巨大成功.本文将重点介绍深度学习在物体识别.物体检测.视频分析的最 ...

  4. 深度学习在图像识别中的发展进程与展望

    本文是转载,出自:http://blog.csdn.net/linj_m/article/details/46351053点击打开链接 深度学习是近十年来人工智能领域取得的最重要的突破之一.它在语音识 ...

  5. ROS学习手记 - 5 理解ROS中的基本概念_Services and Parameters

    ROS学习手记 - 5 理解ROS中的基本概念_Services and Parameters 上一节完成了对nodes, Topic的理解,再深入一步: Services and Parameter ...

  6. scala学习手记2 - scala中的循环

    先来看一段Java中的循环: for (int i = 1; i < 4; i++) {System.out.print(i + ","); } 毫无疑问,scala可以让这 ...

  7. ActionScript 学习手记之ExternalInterface的使用

    Flash ActionScript 学习手记之ExternalInterface的使用回家之前接到来自学校软件协会的一个开发任务,要求实现.Net与Flash之间的相互操作,具体要求实现C#对fla ...

  8. AM335X的汇编语言与c语言,X86汇编语言学习手记 -- 汇编和C协同

    X86汇编语言学习手记(3) 2004年12月 在X86汇编语言学习手记(1)(2)中,可以看到栈(Stack)作为进程执行过程中数据的临时存储区域,通常包含如下几类数据: 局部变量 函数调用的返回地 ...

  9. webpack入门学习手记(一)

    本人微信公众号:前端修炼之路,欢迎关注. 之前用过gulp.grunt,但是一直没有学习过webpack.这两天刚好有时间,学习了下webpack.webpack要想深入研究,配置的东西比较多,网上的 ...

最新文章

  1. 【前沿技术】“中国天眼”观测到宇宙极端爆炸起源证据
  2. ReactJS入门之声明周期
  3. jvm 启动参数设置
  4. U盘 制作 win 7 64bit 旗舰版 安装盘
  5. 如何在家访问公司的文件服务器,企业的共享文件,该怎么高效管理?
  6. python物理引擎模拟三体_一个物理引擎能不能模拟少量粒子之间的力?
  7. 40vf什么意思_变频器的VF模式是什么意思?VF什么意思
  8. mysql null 查询条件_MySql当查询条件为空时不作为条件查询
  9. 001_关于选中的磁盘具有MBR分区表。在 EFI 系统上,Windows 只能安装到 GPT 磁盘。问题解决
  10. grafana zabbix 模板_【Grafana教程】安装Grafana并配置Zabbix数据源
  11. 如何保护Mac的数据安全?
  12. mysql好玩的代码_搞一些好玩的东西redis
  13. 磁珠 符号_史上最全面的磁珠知识大全
  14. linux下的etc是什么意思
  15. 伪装成抖音国际版Tiktok的短信蠕虫(病毒分析)
  16. 电信计费综合管理系统
  17. 推荐学习方法——费曼技巧,以教促学,教学相长
  18. 智能合约安全测试指南
  19. 查看SQL查询数据所话费时间
  20. 关于前端开发中“模块”和“组件”概念的思考

热门文章

  1. pairproject总结和结果
  2. myrio与fpga编程_【虚拟课堂】LabVIEW与MyRIO的逐点比较法插补实现(含FPGA)
  3. 倒F天线仿真及走线宽度和高度对天线参数的影响
  4. 关于SQLAlchemy的警告Warning: (1366, “Incorrect string value: ‘\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...‘ for colu
  5. compressor压缩_使用Compressor.io压缩和优化图像高达90%
  6. blob开头的文件下载_Blob下载文件流
  7. 使用esp8266作为I2C传感器的主机
  8. segy地震数据的读取python_Python-segy格式地震资料segyio读写包说明(二),pythonsegy,数据,学习,笔记...
  9. 小鱼易连发布全新智能会议终端产品 引领云视频会议市场
  10. 【AD】AD20生成PCB制板文件Gerber