I am fairly new to NS3. In ns3 v3.39, when I am trying to run a virtual simulation for third.cc program in the example folder using XML file on NetAnim, it is showing no packet transfer between AP and mobile WiFi nodes, however, it is showing the the packet transfer between P2P nodes and CSMA nodes. How can I resolve the issue and what changes do I need to make?
The given below code is a somewhat modified code of third.cc where I have taken two P2P connections each with 2 nodes having 1 node as common, 1 LAN connection with 1 node from one of the P2P connections and 1 WiFi network with 1 P2P node as AP and 4 WiFi devices.
#include "ns3/applications-module.h"
#include "ns3/core-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/ssid.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/netanim-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("Assignmet2Q1");
int main(int argc, char* argv[])
{
uint32_t nCsma = 2;
uint32_t nWifi = 4;
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
//p2p connection between R1-R2
NodeContainer p2pNodes1;
p2pNodes1.Create(2);
PointToPointHelper p2P;
p2P.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
p2P.SetChannelAttribute("Delay", StringValue("4ms"));
NetDeviceContainer p2pDevices;
p2pDevices = p2P.Install(p2pNodes1);
//p2p connection between R1-C1
NodeContainer p2pNodes2;
p2pNodes2.Add(p2pNodes1.Get(0));//R1
p2pNodes2.Create(1);//C1
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("4ms"));
NetDeviceContainer p2pDevices1;
p2pDevices1 = p2p.Install(p2pNodes2);
//Ethernet connection between R2-C2, R2-C3
NodeContainer csmaNodes;
csmaNodes.Add(p2pNodes1.Get(1));//R2
csmaNodes.Create(nCsma);//C2,C3
CsmaHelper csma;
csma.SetChannelAttribute("DataRate", StringValue("100Mbps"));
csma.SetChannelAttribute("Delay", TimeValue(NanoSeconds(5000)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install(csmaNodes);
//Wifi creation R1-W1,W2,W3,W4
NodeContainer wifiStaNodes;
wifiStaNodes.Create(nWifi); //W1,W2,W3,W4
NodeContainer wifiApNode = p2pNodes1.Get(0); //R1
//Channel creation
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy;
phy.SetChannel(channel.Create());
//Used to configure and manage Wi-Fi MAC parameters in an ns-3
WifiMacHelper mac;
Ssid ssid = Ssid("ns-3-ssid");
WifiHelper wifi;
NetDeviceContainer staDevices;
mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
staDevices = wifi.Install(phy, mac, wifiStaNodes);
NetDeviceContainer apDevices;
mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
apDevices = wifi.Install(phy, mac, wifiApNode);
//Set mobility of the WiFi nodes
MobilityHelper mobility;
mobility.SetPositionAllocator("ns3::GridPositionAllocator",
"MinX", DoubleValue(0.0),
"MinY", DoubleValue(0.0),
"DeltaX", DoubleValue(5.0),
"DeltaY", DoubleValue(10.0),
"GridWidth", UintegerValue(3),
"LayoutType", StringValue("RowFirst"));
mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel", "Bounds", RectangleValue(Rectangle(-50, 50, -50, 50)));
mobility.Install(wifiStaNodes);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(wifiApNode);
//The Internet Stack includes the networking protocols and configurations necessary for nodes to communicate over the Internet
InternetStackHelper stack;
stack.Install(csmaNodes);
stack.Install(wifiApNode);
stack.Install(wifiStaNodes);
stack.Install(p2pNodes1.Get(1));
Ipv4AddressHelper address;
address.SetBase("192.168.10.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign(p2pDevices);
address.SetBase("192.168.20.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces1;
p2pInterfaces = address.Assign(p2pDevices);
address.SetBase("192.168.30.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign(csmaDevices);
address.SetBase("192.168.40.0", "255.255.255.0");
address.Assign(staDevices);
address.Assign(apDevices);
UdpEchoServerHelper echoServer(10);
ApplicationContainer serverApps = echoServer.Install(csmaNodes.Get(nCsma));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(csmaInterfaces.GetAddress(nCsma), 10);
echoClient.SetAttribute("MaxPackets", UintegerValue(1));
echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
echoClient.SetAttribute("PacketSize", UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(wifiStaNodes.Get(nWifi-1));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Stop(Seconds(10.0));
AnimationInterface anim("a2.xml");
anim.SetConstantPosition(p2pNodes2.Get(1),0,25);
anim.SetConstantPosition(csmaNodes.Get(0),20,15);
anim.SetConstantPosition(csmaNodes.Get(1),10,25);
anim.SetConstantPosition(csmaNodes.Get(2),20,25);
anim.SetConstantPosition(wifiStaNodes.Get(0),0,10);
anim.SetConstantPosition(wifiStaNodes.Get(1),2,10);
anim.SetConstantPosition(wifiStaNodes.Get(2),4,10);
anim.SetConstantPosition(wifiStaNodes.Get(3),6,10);
anim.SetConstantPosition(wifiApNode.Get(0),10,15);
Simulator::Run();
Simulator::Destroy();
return 0;
}
The packet getting stuck at AP and not broadcasting to WiFi nodes:
Is there a way to solve the problem with the XML simulation to see the packet transfer between AP and WiFi devices?
