我使用的是 Ubuntu 22.04 版,并尝试使用 ns-3 3.38 运行一个脚本来设置网状无线网络。但是运行后出现错误。
错误:“Default”不是“ns3:YansiWifiHelper”的成员
错误:此范围内未声明‘WIFI_PHY_STANDARD_80211N_5GHZ’
我将提供不带头文件的脚本。我有两个错误,我会标记出这些行。
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("SimpleMeshNetwork");
int main(int argc, char *argv[]) {
LogComponentEnable("SimpleMeshNetwork", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create(4);
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::GridPositionAllocator",
"MinX", DoubleValue(0.0),
"MinY", DoubleValue(0.0),
"DeltaX", DoubleValue(100.0),
"DeltaY", DoubleValue(100.0),
"GridWidth", UintegerValue(2),
"LayoutType", StringValue("RowFirst"));
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
WifiHelper wifi;
wifi.SetStandard(WIFI_PHY_STANDARD_80211s);
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
"DataMode", StringValue("OfdmRate6Mbps"));
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.Set("ChannelNumber", UintegerValue(7));
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
MeshHelper mesh = MeshHelper::Default();
mesh.SetStackInstaller("ns3::Dot11sStack");
mesh.SetSpreadInterfaceChannels(MeshHelper::SPREAD_CHANNELS);
mesh.SetMacType("RandomStart", TimeValue(Seconds(0.1)));
NetDeviceContainer meshDevices = mesh.Install(wifiPhy, nodes);
InternetStackHelper internet;
internet.Install(nodes);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign(meshDevices);
Simulator::Stop(Seconds(10.0));
for (uint32_t i = 0; i < nodes.GetN(); ++i) {
Ptr<Node> node = nodes.Get(i);
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
Ipv4InterfaceAddress iaddr = ipv4->GetAddress(1, 0);
Ipv4Address addr = iaddr.GetLocal();
NS_LOG_INFO("Node " << i << " has IP address " << addr);
}
Simulator::Run();
Simulator::Destroy();
return 0;
}
How to solve such errors?
答案1
wifi.SetStandard(ns3::WIFI_STANDARD_80211n);
n3.38
如果您需要在不指定频带的情况下书写,请尝试使用此行。