我一直在 NS-3 中尝试使用 wifi ad-hoc 网络,目前正在尝试证明两个节点所在的距离越远,连接就越差。运行 WAF 时没有编译或运行时错误。
问题:
虽然我尝试过使用默认构造函数(据说它设置了 的传播损失模型ns3::LogDistancePropagationLossModel
),但当距离改变时,对节点之间的传输带宽以及网络抖动或延迟都没有影响。然后我尝试手动设置传播损失,当距离设置为大于 1.0 时导致没有连接。我对这种行为感到很困惑。我觉得我的代码中遗漏了一些应该传递给 ns-3 但似乎找不到的值。我引用了示例代码但无济于事(http://www.nsnam.org/doxygen/wifi-example-sim_8cc_source.html)。
我在 udp 模式下使用 iperf 来测量连接统计信息。我有两个正确隔离的 linux 容器,可以通过 WAF 脚本通过 ns-3 进行通信。
资源:
#include <iostream>
#include <fstream>
#include"ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/tap-bridge-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
using namespace ns3;
int main( int argc, char *argv[]){
uint32_t nNodes = 2;
CommandLine cmd;
cmd.Parse (argc, argv);
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
NodeContainer nodes;
nodes.Create(nNodes);
CsmaHelper csma;
//csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
WifiHelper wifi = WifiHelper::Default();
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
//wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
//wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");
wifiChannel.AddPropagationLoss("ns3::LogDistancePropagationLossModel","Exponent", DoubleValue (3.0));
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate54Mbps"), "ControlMode",StringValue ("OfdmRate54Mbps"));
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (10.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
TapBridgeHelper wifiTapBridge;
wifiTapBridge.SetAttribute ("Mode", StringValue ("UseLocal"));
NodeContainer n_1 = NodeContainer(nodes.Get(0), nodes.Get(1));
NetDeviceContainer dev_1 = wifi.Install(wifiPhy,wifiMac,n_1);
wifiTapBridge.SetAttribute ("DeviceName", StringValue ("tap-0"));
wifiTapBridge.Install(nodes.Get(0), dev_1.Get(0));
wifiTapBridge.SetAttribute ("DeviceName", StringValue ("tap-1"));
wifiTapBridge.Install(nodes.Get(1), dev_1.Get(1));
// Run the simulation for 1 minute to give the user time to play around
Simulator::Stop (Seconds (600.));
csma.EnablePcapAll("radio",true);
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);Simulator::Run ();
Simulator::Destroy ();
}
编辑: 只是想更新情况。通过禁用碎片并且不尝试覆盖默认的传播损失模型,我能够注意到连接随距离的变化。作为参考,Ofdm 速率 54Mbps 的连接下降距离为 27-30 米,Ofdm 速率 24Mbps 的距离为 55-60m。
这仍然让我指出,当我试图“覆盖”或在 sim 上添加传播损失模型时,我会在 1m 的距离之外失去连接。我尝试使用 Friis、默认的 Log Distance 和 Kun2600 进行覆盖,并且都具有相同的效果。工作代码如下。
谢谢,迈克
#include <iostream>
#include <fstream>
#include"ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/tap-bridge-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
using namespace ns3;
int main( int argc, char *argv[]){
uint32_t nNodes = 2;
CommandLine cmd;
cmd.Parse (argc, argv);
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
NodeContainer nodes;
nodes.Create(nNodes);
CsmaHelper csma;
//csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
WifiHelper wifi = WifiHelper::Default();
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
//wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
//wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
//wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
//wifiPhy.Set ("RxGain", DoubleValue (0) );
//wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (-80));
//wifiChannel.AddPropagationLoss("ns3::Kun2600MhzPropagationLossModel");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate24Mbps"));
//wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
Ptr<YansWifiChannel> chan = wifiChannel.Create();
wifiPhy.SetChannel (chan);
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
positionAlloc->Add (Vector (58.0, 0.0, 0.0));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
TapBridgeHelper wifiTapBridge;
wifiTapBridge.SetAttribute ("Mode", StringValue ("UseLocal"));
NodeContainer n_1 = NodeContainer(nodes.Get(0), nodes.Get(1));
NetDeviceContainer dev_1 = wifi.Install(wifiPhy,wifiMac,n_1);
wifiTapBridge.SetAttribute ("DeviceName", StringValue ("tap-0"));
wifiTapBridge.Install(nodes.Get(0), dev_1.Get(0));
wifiTapBridge.SetAttribute ("DeviceName", StringValue ("tap-1"));
wifiTapBridge.Install(nodes.Get(1), dev_1.Get(1));
// Run the simulation for 1 minute to give the user time to play around
Simulator::Stop (Seconds (600.));
csma.EnablePcapAll("radio",true);
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);Simulator::Run ();
Simulator::Destroy ();
}