NS-3 学习之信号传播损失模型之RangePropagationLossModel范围传播损失模型

信号覆盖范围或者信息传输范围与传播损失模型有关,下面介绍一下ns-3 中的传播损失模型:
在源码包中的/src/propagation/doc/propagation.rst 文档里有相关说明。目前ns-3 实现了的传播损失模型有:
The following propagation loss models are implemented:
   * Cost231PropagationLossModel
   * FixedRssLossModel
   * FriisPropagationLossModel
   * ItuR1411LosPropagationLossModel
   * ItuR1411NlosOverRooftopPropagationLossModel
   * JakesPropagationLossModel
   * Kun2600MhzPropagationLossModel
   * LogDistancePropagationLossModel
   * MatrixPropagationLossModel
   * NakagamiPropagationLossModel
   * OkumuraHataPropagationLossModel
   * RandomPropagationLossModel
   * RangePropagationLossModel
   * ThreeLogDistancePropagationLossModel
   * TwoRayGroundPropagationLossModel
   * ThreeGppPropagationLossModel

   * ThreeGppRMaPropagationLossModel
   * ThreeGppUMaPropagationLossModel
   * ThreeGppUmiStreetCanyonPropagationLossModel
   * ThreeGppIndoorOfficePropagationLossModel

选我可能涉及到的几个模型翻译下:
【1.FixedRssLossModel】,固定RSS(RSS: received signal strength, 接收信号强度)损失模型
Return a constant received power level independent of the transmit power.
返回与发射功率无关的恒定接收功率电平。
个人理解并结合仿真调试,应该是设置这种损失模型后,只要信号强度RSS 设置为大于某个阈值,无论节点间距离多远,都可以通信。
2.ItuR1411LosPropagationLossModel
This class implements the ITU-R 1411 LOS propagation model for Line-of-Sight (LoS) short range outdoor communication in the frequency range 300 MHz to 100 GHz. 
For more information about the model, please see the propagation module documentation in .rst format.
此类实现 ITU-R 1411 LOS 传播模型,用于 300 MHz 至 100 GHz 频率范围内的视距 (LoS) 短距离户外通信。
有关模型的更多信息,请参阅 .rst 格式的传播模块文档。
3.ItuR1411NlosOverRooftopPropagationLossModel
This class implements the ITU-R 1411 LOS propagation model for Non-Line-of-Sight (NLoS) short range outdoor communication over rooftops in the frequency range 300 MHz to 100 GHz. 
For more information about the model, please see the propagation module documentation in .rst format.
此类实现了 ITU-R 1411 LOS 传播模型,用于在 300 MHz 至 100 GHz 频率范围内在屋顶上进行的非视距 (NLoS) 短距离户外通信。
有关模型的更多信息,请参阅 .rst 格式的传播模块文档。
【4.LogDistancePropagationLossModel】
a log distance propagation model.
This model calculates the reception power with a so-called log-distance propagation model: $ L = L_0 + 10 n log_{10}(\frac{d}{d_0})$
对数距离传播模型。
该模型使用所谓的对数距离传播模型计算接收功率: $ L = L_0 + 10 n log_{10}(\frac{d}{d_0})$
【5.MatrixPropagationLossModel,矩阵传播损失模型】
The propagation loss is fixed for each pair of nodes and doesn't depend on their actual positions.
每对节点的传播损耗是固定的,不取决于它们的实际位置。
This is supposed to be used by synthetic tests. Note that by default propagation loss is assumed to be symmetric.
这应该由合成测试使用。 请注意,默认情况下,传播损耗假定为对称的。
6.RandomPropagationLossModel,随机传播损失模型
The propagation loss follows a random distribution.
传播损耗遵循随机分布。
【7.RangePropagationLossModel,范围传播损失模型】
The propagation loss depends only on the distance (range) between transmitter and receiver.
传播损耗仅取决于发射器和接收器之间的距离(范围)。
The single MaxRange attribute (units of meters) determines path loss. Receivers at or within MaxRange meters receive the transmission at the transmit power level. Receivers beyond MaxRange receive at power -1000 dBm (effectively zero).
单个 MaxRange 属性(以米为单位)确定路径损耗。 MaxRange 仪表处或内部的接收器以发射功率水平接收传输。 超出 MaxRange 的接收器以 -1000 dBm(实际上为零)的功率接收。
8.ThreeLogDistancePropagationLossModel,三对数距离传播损失模型
A log distance path loss propagation model with three distance fields.
具有三个距离场的对数距离路径损耗传播模型。
This model is the same as ns3::LogDistancePropagationLossModel except that it has three distance fields: near, middle and far with different exponents.
该模型与 ns3::LogDistancePropagationLossModel 相同,只是它具有三个距离场:近、中和远,具有不同的指数。
参考:
ns-3 Propagation Loss Models传播模型比较 - 知乎
https://zhuanlan.zhihu.com/p/385648248
ns-3: Class Index
https://www.nsnam.org/doxygen/classes.html
NS3仿真wifi网络环境 - NS3中无线节点的通信传输范围如何设置? - 常给自己加个油 - 博客园
https://www.cnblogs.com/zywnnblog/p/13468568.html

下面重点仿真调试下RangePropagationLossModel,范围传播损失模型:

/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2009 The Boeing Company
 *
 * 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
 *
 */

// This script configures two nodes on an 802.11b physical layer, with
// 802.11b NICs in adhoc mode, and by default, sends one packet of 1000
// (application) bytes to the other node.  The physical layer is configured
// to receive at a fixed RSS (regardless of the distance and transmit
// power); therefore, changing position of the nodes has no effect.
// 节点间的信号强度RSS 是固定的,所以更改节点间的位置(距离)是不会影响节点间的信号传输的。
// There are a number of command-line options available to control
// the default behavior.  The list of available command-line options
// can be listed with the following command:
// ./waf --run "wifi-simple-adhoc --help"
// 有一些有用的命令行选项可供使用
//
// For instance, for this configuration, the physical layer will
// stop successfully receiving packets when rss drops below -97 dBm.
// To see this effect, try running:
// 例如:
// ./waf --run "wifi-simple-adhoc --rss=-97 --numPackets=20"
// ./waf --run "wifi-simple-adhoc --rss=-98 --numPackets=20"
// ./waf --run "wifi-simple-adhoc --rss=-99 --numPackets=20"
//
// Note that all ns-3 attributes (not just the ones exposed in the below
// script) can be changed at command line; see the documentation.
// 请注意,所有 ns-3 属性(不仅仅是下面公开的那些脚本)可以在命令行更改; 请参阅文档。
// This script can also be helpful to put the Wifi layer into verbose
// logging mode; this command will turn on all wifi logging:
// 该脚本还有助于将 Wifi 层置于详细日志记录模式; 此命令将打开所有 wifi 日志记录:
// ./waf --run "wifi-simple-adhoc --verbose=1"
//
// When you are done, you will notice two pcap trace files in your directory.
// If you have tcpdump installed, you can try this:
// 完成后,您会注意到目录中有两个 pcap 跟踪文件。可以使用tcpdump 打开。
// tcpdump -r wifi-simple-adhoc-0-0.pcap -nn -tt
//
//Jerry:修改源码目的主要是测试RangePropagationLossModel,确定信息传输范围。
#include "ns3/command-line.h"
#include "ns3/config.h"
#include "ns3/double.h"
#include "ns3/string.h"
#include "ns3/log.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/mobility-helper.h"
#include "ns3/ipv4-address-helper.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/mobility-model.h"
#include "ns3/internet-stack-helper.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE("WifiSimpleAdhoc");

void ReceivePacket(Ptr<Socket> socket) {
	Address from;
	while (socket->RecvFrom(from)) {
//		std::string nodeId = std::to_string(socket->GetNode()->GetId());
		NS_LOG_UNCOND(
				"Node" << socket->GetNode()->GetId()<< " Received one packet from " <<InetSocketAddress::ConvertFrom (from).GetIpv4 ());
	}
}

static void GenerateTraffic(Ptr<Socket> socket, uint32_t pktSize,
		uint32_t pktCount, Time pktInterval) {
	if (pktCount > 0) {
		socket->Send(Create<Packet>(pktSize));
		//迭代发数据
		Simulator::Schedule(pktInterval, &GenerateTraffic, socket, pktSize,
				pktCount - 1, pktInterval);
	} else {
		socket->Close();
	}
}

int main(int argc, char *argv[]) {
	std::string phyMode("DsssRate1Mbps");
	double rss = -81;  // -dBm Jerry:经测试,最小是-81,低于-81则通信不正常。
	uint32_t packetSize = 1000; // bytes
	uint32_t numPackets = 20;
	double interval = 1.0; // seconds
	bool verbose = false;

	CommandLine cmd(__FILE__);
	cmd.AddValue("phyMode", "Wifi Phy mode", phyMode);
	cmd.AddValue("rss", "received signal strength", rss);
	cmd.AddValue("packetSize", "size of application packet sent", packetSize);
	cmd.AddValue("numPackets", "number of packets generated", numPackets);
	cmd.AddValue("interval", "interval (seconds) between packets", interval);
	cmd.AddValue("verbose", "turn on all WifiNetDevice log components",
			verbose);
	cmd.Parse(argc, argv);
// Convert to time object
	Time interPacketInterval = Seconds(interval);

// Fix non-unicast data rate to be the same as that of unicast
// 设定非单播数据速率与单播相同
	Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode",
			StringValue(phyMode));

	NodeContainer c;
	c.Create(3);	//创建两个节点

// The below set of helpers will help us to put together the wifi NICs we want
// 下面的一组助手将帮助我们把我们想要的 wifi 网卡放在一起
	WifiHelper wifi;
	if (verbose) {
		wifi.EnableLogComponents();  // Turn on all Wifi logging
	}
	wifi.SetStandard(WIFI_STANDARD_80211b);

	YansWifiPhyHelper wifiPhy;
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
//这是使用 FixedRssLossModel 时重要的一个参数,将其设置为零; 否则,将增加增益
	wifiPhy.Set("RxGain", DoubleValue(0));
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
// ns-3 支持 802.11b 的 RadioTap 和 Prism 跟踪扩展
	wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);

	YansWifiChannelHelper wifiChannel;
	wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed regardless
// of the distance between the two stations, and the transmit power
	/*
	 * 下面的 FixedRssLossModel 将导致 rss 固定,无论两个站之间的距离如何,以及发射功率
	 * Jerry:也即两节点之间距离不管多大,都能以设置的rss 信号强度进行通信。
	 */
//	wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss",
//			DoubleValue(rss));
	wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel", "MaxRange",
			DoubleValue(50));

	wifiPhy.SetChannel(wifiChannel.Create());

// Add a mac and disable rate control,添加一个mac并禁用速率控制
	WifiMacHelper wifiMac;
	wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
			StringValue(phyMode), "ControlMode", StringValue(phyMode));
// Set it to adhoc mode,设置为adhoc 模式
	wifiMac.SetType("ns3::AdhocWifiMac");
	NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, c);

// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
// 请注意,对于 FixedRssLossModel,以下位置不用于接收信号强度。
// Jerry:再次强调在固定信号强度模式下,节点的位置关系对信号强弱没有影响
	MobilityHelper mobility;
	Ptr<ListPositionAllocator> positionAlloc = CreateObject<
			ListPositionAllocator>();
	positionAlloc->Add(Vector(50.0, 50.0, 0.0));
	positionAlloc->Add(Vector(100.0, 50.0, 0.0));
	positionAlloc->Add(Vector(50.0, 100.0, 0.0));
	mobility.SetPositionAllocator(positionAlloc);
	mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); //恒定位置移动模型
	mobility.Install(c);

	InternetStackHelper internet;
	internet.Install(c);	//安装internet 协议栈

	Ipv4AddressHelper ipv4;
	NS_LOG_INFO("Assign IP Addresses.");
	ipv4.SetBase("10.1.1.0", "255.255.255.0");
	Ipv4InterfaceContainer i = ipv4.Assign(devices);

	TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");

	Ptr<Socket> source = Socket::CreateSocket(c.Get(0), tid);	//源socket
//255.255.255.255,广播地址;80,端口号
	InetSocketAddress remote = InetSocketAddress(Ipv4Address("255.255.255.255"),
			80);
	source->SetAllowBroadcast(true);
	source->Connect(remote);

	Ptr<Socket> source1 = Socket::CreateSocket(c.Get(1), tid);	//源socket
	source1->SetAllowBroadcast(true);
	source1->Connect(remote);

	Ptr<Socket> recvSink0 = Socket::CreateSocket(c.Get(0), tid);	//目的socket
	InetSocketAddress local0 = InetSocketAddress(Ipv4Address::GetAny(), 80);
	recvSink0->Bind(local0);
	recvSink0->SetRecvCallback(MakeCallback(&ReceivePacket));

	Ptr<Socket> recvSink1 = Socket::CreateSocket(c.Get(1), tid);	//目的socket
	InetSocketAddress local1 = InetSocketAddress(Ipv4Address::GetAny(), 80);
	recvSink1->Bind(local1);
	recvSink1->SetRecvCallback(MakeCallback(&ReceivePacket));

	Ptr<Socket> recvSink2 = Socket::CreateSocket(c.Get(2), tid);	//目的socket
	InetSocketAddress local2 = InetSocketAddress(Ipv4Address::GetAny(), 80);
	recvSink2->Bind(local2);
	recvSink2->SetRecvCallback(MakeCallback(&ReceivePacket));

// Tracing
	wifiPhy.EnablePcap("wifi-simple-adhoc", devices);

// Output what we are doing
	NS_LOG_UNCOND(
			"Testing " << numPackets << " packets sent with receiver rss " << rss);

	Simulator::ScheduleWithContext(source->GetNode()->GetId(), Seconds(1.0),
			&GenerateTraffic, source, packetSize, numPackets,
			interPacketInterval);

	Simulator::ScheduleWithContext(source1->GetNode()->GetId(),
			Seconds(1.00001), &GenerateTraffic, source1, packetSize, numPackets,
			interPacketInterval);

	Simulator::Run();
	Simulator::Destroy();

	return 0;
}

该代码的整体分析见:

(20条消息) NS-3 学习之wifi-simple-adhoc.cc 分析和变种_Jerry_liu20080504的专栏-CSDN博客
https://blog.csdn.net/Jerry_liu20080504/article/details/122683944

在此基础上将损失模型由原来的FixedRssLossModel 改为RangePropagationLossModel,如:

//    wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss",
//            DoubleValue(rss));
    wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel", "MaxRange",
            DoubleValue(50));

仿真试验表明确如文档说明,设置范围即在MaxRange 范围内能通信,超出则无法通信。

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里我提供一个基于ns-3的Propagation Loss Models传播模型性能仿真的代码示例,其中使用了Log-Distance Path Loss Model传播模型。 ```c++ #include "ns3/core-module.h" #include "ns3/network-module.h" #include "ns3/mobility-module.h" #include "ns3/wifi-module.h" #include "ns3/internet-module.h" #include "ns3/applications-module.h" #include "ns3/netanim-module.h" #include "ns3/flow-monitor-module.h" #include "ns3/propagation-loss-model.h" #include "ns3/log-distance-propagation-loss-model.h" using namespace ns3; NS_LOG_COMPONENT_DEFINE ("WifiPropagationLoss"); int main (int argc, char *argv[]) { LogComponentEnable ("WifiPropagationLoss", LOG_LEVEL_INFO); // Create nodes NodeContainer nodes; nodes.Create (2); // Create mobility model MobilityHelper mobility; mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0), "MinY", DoubleValue (0.0), "DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue (5.0), "GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst")); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (nodes); // Create propagation loss model Ptr<LogDistancePropagationLossModel> loss = CreateObject<LogDistancePropagationLossModel> (); loss->SetReference (1.0); // reference distance loss->SetExponent (2.0); // path loss exponent loss->SetFrequency (2.4e9); // signal frequency // Create wifi devices and install them to the nodes WifiHelper wifi; wifi.SetStandard (WIFI_PHY_STANDARD_80211b); wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("DsssRate1Mbps"), "ControlMode", StringValue ("DsssRate1Mbps")); WifiMacHelper mac; mac.SetType ("ns3::AdhocWifiMac"); NetDeviceContainer devices = wifi.Install (mac, nodes); devices.Get (0)->GetObject<WifiNetDevice> ()->SetPropagationLossModel (loss); devices.Get (1)->GetObject<WifiNetDevice> ()->SetPropagationLossModel (loss); // Install internet stack InternetStackHelper stack; stack.Install (nodes); // Assign IP addresses Ipv4AddressHelper address; address.SetBase ("10.1.1.0", "255.255.255.0"); Ipv4InterfaceContainer interfaces = address.Assign (devices); // Create UDP echo server UdpEchoServerHelper echoServer (9); ApplicationContainer serverApps = echoServer.Install (nodes.Get (1)); serverApps.Start (Seconds (1.0)); serverApps.Stop (Seconds (10.0)); // Create UDP echo client and send packets UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); echoClient.SetAttribute ("MaxPackets", UintegerValue (10)); echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (nodes.Get (0)); clientApps.Start (Seconds (2.0)); clientApps.Stop (Seconds (10.0)); // Enable pcap tracing wifi.EnablePcapAll ("wifi-propagation-loss"); // Create animation AnimationInterface anim ("wifi-propagation-loss.xml"); anim.SetConstantPosition (nodes.Get (0), 1.0, 1.0); anim.SetConstantPosition (nodes.Get (1), 2.0, 2.0); // Enable flow monitor Ptr<FlowMonitor> flowMonitor; FlowMonitorHelper flowHelper; flowMonitor = flowHelper.InstallAll (); // Run simulation Simulator::Stop (Seconds (11.0)); Simulator::Run (); // Print flow monitor statistics flowMonitor->CheckForLostPackets (); Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier ()); std::map<FlowId, FlowMonitor::FlowStats> stats = flowMonitor->GetFlowStats (); for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i) { Ipv4FlowClassifier::FiveTuple tuple = classifier->FindFlow (i->first); NS_LOG_INFO ("Flow " << i->first << " (" << tuple.sourceAddress << " -> " << tuple.destinationAddress << ")"); NS_LOG_INFO (" Tx Bytes: " << i->second.txBytes); NS_LOG_INFO (" Tx Packets: " << i->second.txPackets); NS_LOG_INFO (" Rx Bytes: " << i->second.rxBytes); NS_LOG_INFO (" Rx Packets: " << i->second.rxPackets); NS_LOG_INFO (" Throughput: " << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds () - i->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 << " Mbps"); } // Cleanup Simulator::Destroy (); return 0; } ``` 以上代码中,我们创建了两个节点,并在节点上安装了Wifi设备和传播模型。然后我们创建了一个UDP echo server和一个UDP echo client,并在仿真过程中发送了10个数据包。同时,我们使用了NetAnim工具生成了一个动画,并使用FlowMonitor统计了网络吞吐量等性能指标。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值