zoukankan      html  css  js  c++  java
  • ns-3 OnOffApplication

    关于ns-3 OnOffApplication的使用,主要通过以下几个语句的设置:

    //设置目的IP地址,及端口号

    OnOffHelper onoffA1 ("ns3::UdpSocketFactory",
    Address (InetSocketAddress (Ipv4Address ("10.1.1.2"), 1)));

    //设置发送速率
    onoffA1.SetConstantRate (DataRate ("1Mb/s"));

    //onOffApplication是“open”“close”的模式交替工作的,这里设置“open”的时间,和“close”的时间。

    onoffA1.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
    onoffA1.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); 

    //将此APP安装到节点上

    ApplicationContainer appA1 = onoffA1.Install (terminals.Get (2));

    //设置APP的开始时间和结束时间

    appA1.Start (Seconds (0.0));
    appA1.Stop (Seconds (2.0));

     

    这里需要注意的是:需要先设置发送速率,再设置"OnTime""OffTime"时间。原因:

    void
    OnOffHelper::SetConstantRate (DataRate dataRate, uint32_t packetSize)
    {
    m_factory.Set ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1000]"));
    m_factory.Set ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
    m_factory.Set ("DataRate", DataRateValue (dataRate));
    m_factory.Set ("PacketSize", UintegerValue (packetSize));
    }

    这是ns-3的SetConstantRate()函数的实现,如果先设置"OnTime""OffTime"时间,再设置发送速率,则在SetConstantRate()函数内部会修改之前设置的"OnTime""OffTime"时间,导致前面的设置不能生效。

  • 相关阅读:
    原生js系列 删除元素
    事件绑定的几种方式
    js的五种输出方式
    三、浏览器事件处理机制--事件循环(event loop)
    二、事件流、事件代理
    一、事件的分类
    js数据类型转换
    html锚点
    观察者模式
    策略模式
  • 原文地址:https://www.cnblogs.com/jingjingblog/p/7293882.html
Copyright © 2011-2022 走看看