问题描述
我想实现csma+wifi模拟。
所以,我正在尝试在 csma 节点上添加 wifi 站堆栈。
但它不起作用..
我该如何解决这个问题?\
我一边看例子(Third.cc),一边写了这段代码。
这个原因,出现错误,我认为在csma堆栈上创建wifi站堆栈。
因此,堆栈在 csma+wifi 节点 (n3) 上重复。\
有没有办法同时在节点(n3)上堆叠两个堆栈?
我的拓扑: enter image description here
n3:csma 和 wifi 站节点
我会在这里上传我的代码。
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/ipv4-global-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("Test");
int main (int argc,char *argv [])
{
uint32_t nWifi = 1;
uint32_t nCsma = 5;
LogComponentEnable ("UdpEchoClientApplication",LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",LOG_LEVEL_INFO);
NodeContainer csmaNodes;
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate",StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay",TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Add (csmaNodes.Get (2));
wifiStaNodes.Add (csmaNodes.Get (3));
NodeContainer wifiApNode;
wifiApNode.Create (nWifi);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac","Ssid",SsidValue (ssid),"ActiveProbing",BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy,mac,wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy,wifiApNode);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator","MinX",DoubleValue (0.0),"MinY","DeltaX",DoubleValue (5.0),"DeltaY",DoubleValue (10.0),"GridWidth",UintegerValue (3),"LayoutType",StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiStaNodes);
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
//stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
//address.SetBase ("10.1.2.0","255.255.255.0");
//Ipv4InterfaceContainer wifistaInterfaces;
//wifistaInterfaces = address.Assign (staDevices);
address.SetBase ("10.1.3.0","255.255.255.0");
Ipv4InterfaceContainer wifiapInterfaces;
wifiapInterfaces = address.Assign (apDevices);
// csma application
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (0),9);
echoClient.SetAttribute ("MaxPackets",UintegerValue (1));
echoClient.SetAttribute ("Interval",TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize",UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (csmaNodes.Get (4));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// wifi application
UdpEchoServerHelper wifiechoServer (15);
ApplicationContainer wifiserverApps = wifiechoServer.Install (wifiApNode.Get (0));
wifiserverApps.Start (Seconds (11.0));
wifiserverApps.Stop (Seconds (16.0));
UdpEchoClientHelper wifiechoClient (wifiapInterfaces.GetAddress (0),15);
wifiechoClient.SetAttribute ("MaxPackets",UintegerValue (1));
wifiechoClient.SetAttribute ("Interval",TimeValue (Seconds (1.0)));
wifiechoClient.SetAttribute ("PacketSize",UintegerValue (1024));
ApplicationContainer wificlientApps = wifiechoClient.Install (wifiStaNodes.Get (1));
wificlientApps.Start (Seconds (12.0));
wificlientApps.Stop (Seconds (16.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (16.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)