关于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"时间,导致前面的设置不能生效。

 

相关文章:

  • 2021-11-30
  • 2021-06-23
  • 2021-11-20
  • 2022-12-23
  • 2022-03-03
  • 2021-08-25
  • 2021-11-15
  • 2021-12-26
猜你喜欢
  • 2022-01-26
  • 2021-07-02
  • 2022-12-23
  • 2020-11-04
  • 2021-05-04
  • 2022-01-23
  • 2021-05-29
相关资源
相似解决方案