Create a Wireless Link between two nodes in ns3 - c++

I have to build a topology where 2 nodes are connected via the wifi network or cellular network.
In ns-3 I can't find examples to do so.
How could I build the topology ?

NS3 has only 4G network modules, WiMax and LTE. NS3 has no 2G or 3G modules.
Here is the example to create topology of a source node sending UDP packet to a sink node with combination of cellular network and Wifi Network.
LTE Network + Wifi Network
#include "ns3/lte-helper.h"
#include "ns3/epc-helper.h"
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wimax-module.h"
#include "ns3/internet-module.h"
#include "ns3/global-route-manager.h"
#include "ns3/ipcs-classifier-record.h"
#include "ns3/service-flow.h"
#include <iostream>
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/point-to-point-helper.h"
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
using namespace ns3;
int main (int argc, char *argv[])
{
Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
bool verbose = false;
int duration = 500, schedType = 0;
uint16_t numberOfUEs=2; //Default number of ues attached to each eNodeB
Ptr<LteHelper> lteHelper; //Define LTE
Ptr<EpcHelper> epcHelper; //Define EPC
NodeContainer remoteHostContainer; //Define the Remote Host
NetDeviceContainer internetDevices; //Define the Network Devices in the Connection between EPC and the remote host
Ptr<Node> pgw; //Define the Packet Data Network Gateway(P-GW)
Ptr<Node> remoteHost; //Define the node of remote Host
InternetStackHelper internet; //Define the internet stack
PointToPointHelper p2ph; //Define Connection between EPC and the Remote Host
Ipv4AddressHelper ipv4h; //Ipv4 address helper
Ipv4StaticRoutingHelper ipv4RoutingHelper; //Ipv4 static routing helper
Ptr<Ipv4StaticRouting> remoteHostStaticRouting;
Ipv4InterfaceContainer internetIpIfaces; //Ipv4 interfaces
CommandLine cmd;
cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
cmd.Parse (argc, argv);
LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer ssNodes;
NodeContainer bsNodes;
ssNodes.Create (2);
bsNodes.Create (1);
uint32_t nCsma = 3;
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, ssNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility1;
mobility1.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"));
mobility1.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility1.Install (wifiApNode);
(wifiApNode.Get(0) -> GetObject<ConstantPositionMobilityModel>()) -> SetPosition(Vector(100.0, 501.0, 0.0));
InternetStackHelper stack1;
stack1.Install (csmaNodes);
stack1.Install (wifiApNode);
stack1.Install (ssNodes);
Ipv4AddressHelper address1;
address1.SetBase ("11.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address1.Assign (p2pDevices);
address1.SetBase ("11.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address1.Assign (csmaDevices);
address1.SetBase ("11.1.3.0", "255.255.255.0");
address1.Assign (staDevices);
address1.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps1 = echoServer.Install (csmaNodes.Get (nCsma));
serverApps1.Start (Seconds (1.0));
serverApps1.Stop (Seconds (duration+0.1));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1000));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps1 =
echoClient.Install (ssNodes.Get (0));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (duration+0.1));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//pointToPoint.EnablePcapAll ("third");
phy.EnablePcap ("third", apDevices.Get (0));
//csma.EnablePcap ("third", csmaDevices.Get (0), true);
lteHelper = CreateObject<LteHelper> ();
epcHelper = CreateObject<EpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
lteHelper->SetAttribute ("PathlossModel",
StringValue ("ns3::FriisPropagationLossModel"));
pgw = epcHelper->GetPgwNode ();
remoteHostContainer.Create (1);
remoteHost = remoteHostContainer.Get (0);
internet.Install (remoteHostContainer);
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
internetDevices = p2ph.Install (pgw, remoteHost);
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
internetIpIfaces = ipv4h.Assign (internetDevices);
remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
std::cout << "2. Installing LTE+EPC+remotehost. Done!" << std::endl;
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc;
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 500.0, 0.0)); //STA
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
mobility.Install(ssNodes.Get(0));
Ptr<ConstantVelocityMobilityModel> cvm = ssNodes.Get(0)->GetObject<ConstantVelocityMobilityModel>();
cvm->SetVelocity(Vector (5, 0, 0)); //move to left to right 10.0m/s
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 500.0, 10.0)); //MAG1AP
positionAlloc->Add (Vector (0.0, 510.0, 0.0)); //MAG2AP
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (NodeContainer(bsNodes.Get(0),ssNodes.Get(1)));
NetDeviceContainer ssDevs, bsDevs;
bsDevs = lteHelper->InstallEnbDevice (bsNodes);
ssDevs=lteHelper->InstallUeDevice (ssNodes);
for (uint16_t j=0; j < numberOfUEs; j++)
{
lteHelper->Attach (ssDevs.Get(j), bsDevs.Get(0));
}
Ipv4InterfaceContainer iueIpIface;
iueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ssDevs));
lteHelper->ActivateEpsBearer (ssDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT), EpcTft::Default ());
UdpServerHelper udpServer;
ApplicationContainer serverApps;
UdpClientHelper udpClient;
ApplicationContainer clientApps;
udpServer = UdpServerHelper (100);
serverApps = udpServer.Install (ssNodes.Get (0));
serverApps.Start (Seconds (6));
serverApps.Stop (Seconds (duration));
udpClient = UdpClientHelper (iueIpIface.GetAddress (0), 100);
udpClient.SetAttribute ("MaxPackets", UintegerValue (200000));
udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.004)));
udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
clientApps = udpClient.Install (remoteHost);
clientApps.Start (Seconds (6));
clientApps.Stop (Seconds (duration));
lteHelper->EnableTraces ();
NS_LOG_INFO ("Starting simulation.....");
Simulator::Stop(Seconds(duration));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}
WiMax Network + Wifi Network
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wimax-module.h"
#include "ns3/internet-module.h"
#include "ns3/global-route-manager.h"
#include "ns3/ipcs-classifier-record.h"
#include "ns3/service-flow.h"
#include <iostream>
NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
using namespace ns3;
int main (int argc, char *argv[])
{
bool verbose = false;
int duration = 1000, schedType = 0;
WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
CommandLine cmd;
cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
cmd.Parse (argc, argv);
LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
switch (schedType)
{
case 0:
scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
break;
case 1:
scheduler = WimaxHelper::SCHED_TYPE_MBQOS;
break;
case 2:
scheduler = WimaxHelper::SCHED_TYPE_RTPS;
break;
default:
scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
}
NodeContainer ssNodes;
NodeContainer bsNodes;
ssNodes.Create (2);
bsNodes.Create (1);
uint32_t nCsma = 3;
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, ssNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility1;
mobility1.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"));
mobility1.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility1.Install (wifiApNode);
(wifiApNode.Get(0) -> GetObject<ConstantPositionMobilityModel>()) -> SetPosition(Vector(800.0, 0.0, 0.0));
InternetStackHelper stack1;
stack1.Install (csmaNodes);
stack1.Install (wifiApNode);
stack1.Install (ssNodes);
Ipv4AddressHelper address1;
address1.SetBase ("11.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address1.Assign (p2pDevices);
address1.SetBase ("11.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address1.Assign (csmaDevices);
address1.SetBase ("11.1.3.0", "255.255.255.0");
address1.Assign (staDevices);
address1.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps1 = echoServer.Install (csmaNodes.Get (nCsma));
serverApps1.Start (Seconds (1.0));
serverApps1.Stop (Seconds (duration));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1000));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps1 =
echoClient.Install (ssNodes.Get (0));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (duration));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//pointToPoint.EnablePcapAll ("third");
phy.EnablePcap ("third", apDevices.Get (0));
//csma.EnablePcap ("third", csmaDevices.Get (0), true);
WimaxHelper wimax;
NetDeviceContainer ssDevs, bsDevs;
ssDevs = wimax.Install (ssNodes,
WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION,
WimaxHelper::SIMPLE_PHY_TYPE_OFDM,
scheduler);
bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION, WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler);
wimax.EnableAscii ("bs-devices", bsDevs);
wimax.EnableAscii ("ss-devices", ssDevs);
Ptr<SubscriberStationNetDevice> ss[2];
for (int i = 0; i < 2; i++)
{
ss[i] = ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ();
ss[i]->SetModulationType (WimaxPhy::MODULATION_TYPE_QAM16_12);
}
Ptr<BaseStationNetDevice> bs;
bs = bsDevs.Get (0)->GetObject<BaseStationNetDevice> ();
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc;
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (-1061.0, 70.0, 0.0)); //STA
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
mobility.Install(ssNodes.Get(0));
Ptr<ConstantVelocityMobilityModel> cvm = ssNodes.Get(0)->GetObject<ConstantVelocityMobilityModel>();
cvm->SetVelocity(Vector (5, 0, 0)); //move to left to right 10.0m/s
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (-0.0, 40.0, 0.0)); //MAG1AP
positionAlloc->Add (Vector (0.0, 40.0, 0.0)); //MAG2AP
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (NodeContainer(bsNodes.Get(0),ssNodes.Get(1)));
InternetStackHelper stack;
stack.Install (bsNodes);
//stack.Install (ssNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer SSinterfaces = address.Assign (ssDevs);
Ipv4InterfaceContainer BSinterface = address.Assign (bsDevs);
if (verbose)
{
wimax.EnableLogComponents (); // Turn on all wimax logging
}
/*------------------------------*/
UdpServerHelper udpServer;
ApplicationContainer serverApps;
UdpClientHelper udpClient;
ApplicationContainer clientApps;
udpServer = UdpServerHelper (100);
serverApps = udpServer.Install (ssNodes.Get (0));
serverApps.Start (Seconds (6));
serverApps.Stop (Seconds (duration));
udpClient = UdpClientHelper (SSinterfaces.GetAddress (0), 100);
udpClient.SetAttribute ("MaxPackets", UintegerValue (1200));
udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.5)));
udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
clientApps = udpClient.Install (ssNodes.Get (1));
clientApps.Start (Seconds (6));
clientApps.Stop (Seconds (duration));
Simulator::Stop (Seconds (duration + 0.1));
wimax.EnablePcap ("wimax-simple-ss0", ssNodes.Get (0)->GetId (), ss[0]->GetIfIndex ());
wimax.EnablePcap ("wimax-simple-ss1", ssNodes.Get (1)->GetId (), ss[1]->GetIfIndex ());
wimax.EnablePcap ("wimax-simple-bs0", bsNodes.Get (0)->GetId (), bs->GetIfIndex ());
IpcsClassifierRecord DlClassifierUgs (Ipv4Address ("0.0.0.0"),
Ipv4Mask ("0.0.0.0"),
SSinterfaces.GetAddress (0),
Ipv4Mask ("255.255.255.255"),
0,
65000,
100,
100,
17,
1);
ServiceFlow DlServiceFlowUgs = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_DOWN,
ServiceFlow::SF_TYPE_RTPS,
DlClassifierUgs);
IpcsClassifierRecord UlClassifierUgs (SSinterfaces.GetAddress (1),
Ipv4Mask ("255.255.255.255"),
Ipv4Address ("0.0.0.0"),
Ipv4Mask ("0.0.0.0"),
0,
65000,
100,
100,
17,
1);
ServiceFlow UlServiceFlowUgs = wimax.CreateServiceFlow (ServiceFlow::SF_DIRECTION_UP,
ServiceFlow::SF_TYPE_RTPS,
UlClassifierUgs);
ss[0]->AddServiceFlow (DlServiceFlowUgs);
ss[1]->AddServiceFlow (UlServiceFlowUgs);
NS_LOG_INFO ("Starting simulation.....");
Simulator::Run ();
ss[0] = 0;
ss[1] = 0;
bs = 0;
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}
The codes is belong to these Author under GPL2 :
https://code.google.com/p/tesis-ns3/source/browse/trunk/lena/scratch/?r=5

Related

How to update the display?

Here is the problem: I am using X11 to track events and then draw on the screen. When the drawing is finished I want do clear all data about the screen, because even if I call XCloseDisplay the application screen behaves weirdly. When I press a key on a keyboard the screen updates and this overlay disappears (I pressed print screen btn). I want to know, how to get this result through code.
while (1)
{
XNextEvent(xdisplay, &xevent);
if (xevent.type == ButtonPress)
{
init_x = xevent.xmotion.x_root;
init_y = xevent.xmotion.y_root;
printf("drawing area: init_x = %d, init_y = %d\n", init_x, init_y);
isPressed = true;
}
else if (xevent.type == ButtonRelease)
{
fin_x = xevent.xmotion.x_root;
fin_y = xevent.xmotion.y_root;
cairo_set_source_surface(cr, surfaceTmp, 1, 1);
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); // The default is CAIRO_FILL_RULE_WINDING.
cairo_rectangle(cr, 0, 0, DisplayWidth(xdisplay, scr), DisplayHeight(xdisplay, scr)); // set rectangle
cairo_fill(cr);
XFlush(xdisplay);
XCloseDisplay(xdisplay);
printf("drawing limit: fin_x = %d, fin_y = %d\n", fin_x, fin_y);
break;
}
if (xevent.type == MotionNotify && isPressed == true)
{
int tmp_x = xevent.xmotion.x_root;
int tmp_y = xevent.xmotion.y_root;
cairo_set_source_rgba(cr, 0, 0, 0, 0.2);
cairo_rectangle(cr, prevInitX, prevInitY, prevFinX, prevFinY);
cairo_fill(cr);
cairo_set_source_surface(cr, surfaceTmp, 1, 1);
cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); // The default is CAIRO_FILL_RULE_WINDING.
cairo_rectangle(cr, init_x, init_y, tmp_x - init_x, tmp_y - init_y); // set rectangle
cairo_fill(cr);
prevInitX = init_x;
prevInitY = init_y;
prevFinX = tmp_x - init_x;
prevFinY = tmp_y - init_y;
}
}

error: ‘Default’ is not a member of ‘ns3::YansWifiPhyHelper’

I'm learning ns-3 on a virtual machine with ubuntu linux 20.04 and ns-3.35. I wrote in c++.
The yans-wifi-helper.h is included in my file.
And I wrote a line as below.
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
But when compiling
root#kotoridsk233-vm:/home/kotoridsk233/ns3_install/ns-allinone-3.35/ns-3.35# ./waf
Waf: Entering directory /home/kotoridsk233/ns3_install/ns-allinone-3.35/ns-3.35/build'
[2968/3038] Compiling scratch/try.cc
../scratch/try.cc: In function ‘int main(int, char**)’:
../scratch/try.cc:30:46: error: ‘Default’ is not a member of ‘ns3::YansWifiPhyHelper’
30 | YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
| ^~~~~~~
Waf: Leaving directory /home/kotoridsk233/ns3_install/ns-allinone-3.35/ns-3.35/build'
Build failed
-> task in 'try' failed with exit status 1 (run with -v to display more information)
However, I read the doc of ns3::YansWifiPhyHelper. Default is one of the static public member functions.
My whole code is as below.(not finish yet)
#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"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("trytodohomework");
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer wifinodes;
wifinodes.Create (100);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default();
phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
phy.SetChannel (channel.Create());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
WifiMacHelper mac;
NetDeviceContainer WifiDevice;
Ssid ssid;
ssid = Ssid ("wifi-network");
phy.Set ("ChannelNumber", UintegerValue (36));
mac.SetType ("ns3::StaWifiMac",
"QosSupported", BooleanValue (true),
"Ssid", SsidValue (ssid));
WifiDevice = wifi.Install (phy, mac, wifinodes.Get (0));
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (100),
"DeltaY", DoubleValue (100),
"GridWidth", UintegerValue (1000),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install(wifinodes);
InternetStackHelper stack;
stack.Install (wifinodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer WifiInterface;
WifiInterface = address.Assign (WifiDevice);
uint16_t port = 9;
UdpEchoServerHelper wifiserver (port);
ApplicationContainer wifiserverApp = wifiserver.Install (wifinodes.Get (0));
wifiserverApp.Start (Seconds (1.0));
wifiserverApp.Stop (Seconds (100.0));
UdpEchoClientHelper echoClient (WifiInterface.GetAddress(1),9);
echoClient.SetAttribute ("DataRate", StringValue ("1000kb/s"));
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1048576));
ApplicationContainer clientApps = echoClient.Install (wifinodes.Get(99));
clientApps.Start (Seconds (1.0));
clientApps.Stop (Seconds (100.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

GlobalRouting Error in combining wireless networks and point to point connection

I am trying to create a network topology of n wireless networks and attach a single node to each of the wifi-ap nodes(as point to point connection) of all wireless networks.
I created an echo application to send datas between the single node(remote node) and one of the wifi nodes.
But I am getting an error as below when i try to run this code
assert failed. cond="w_lsa", file=../src/internet/model/global-route-manager-impl.cc, line=809
terminate called without an active exception
The propose topology is attached as image.topology
How to route the packets in this topology?
Here is the code.
#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/bridge-helper.h"
#include "ns3/netanim-module.h"
#include <vector>
#include <stdint.h>
#include <sstream>
#include <fstream>
using namespace ns3;
int main (int argc, char *argv[])
{
uint32_t nWifis = 2;
uint32_t nStas = 2;
bool sendIp = true;
bool writeMobility = false;
CommandLine cmd;
cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility);
cmd.Parse (argc, argv);
NodeContainer backboneNodes;
NetDeviceContainer backboneDevices;
Ipv4InterfaceContainer backboneInterfaces;
std::vector<NodeContainer> staNodes;
std::vector<NetDeviceContainer> staDevices;
std::vector<NetDeviceContainer> apDevices;
std::vector<Ipv4InterfaceContainer> staInterfaces;
std::vector<Ipv4InterfaceContainer> apInterfaces;
InternetStackHelper stack;
CsmaHelper csma;
Ipv4AddressHelper ip;
ip.SetBase ("192.168.0.0", "255.255.255.0");
backboneNodes.Create (nWifis);
stack.Install (backboneNodes);
backboneDevices = csma.Install (backboneNodes);
double wifiX = 0.0;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
for (uint32_t i = 0; i < nWifis; ++i)
{
// calculate ssid for wifi subnetwork
std::ostringstream oss;
oss << "wifi-default-" << i;
Ssid ssid = Ssid (oss.str ());
NodeContainer remoteHost;
remoteHost.Create(1);
Ptr<Node> remote=remoteHost.Get(0);
Ptr<Node> apnode=backboneNodes.Get(i);
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices = p2p.Install(apnode,remote);
//setup remotenode
stack.Install (remoteHost);
// assign AP IP address to bridge, not wifi
//Ipv4InterfaceContainer
NodeContainer sta;
NetDeviceContainer staDev;
NetDeviceContainer apDev;
Ipv4InterfaceContainer staInterface;
Ipv4InterfaceContainer apInterface;
Ipv4InterfaceContainer remoteInterface;
MobilityHelper mobility;
BridgeHelper bridge;
WifiHelper wifi;
WifiMacHelper wifiMac;
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
sta.Create (nStas);
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (wifiX),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (5.0),
"GridWidth", UintegerValue (1),
"LayoutType", StringValue ("RowFirst"));
// setup the AP.
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (remoteHost);
mobility.Install (backboneNodes.Get (i));
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));
NetDeviceContainer bridgeDev;
bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev, backboneDevices.Get (i)));
// assign AP IP address to bridge, not wifi
apInterface = ip.Assign (bridgeDev);
remoteInterface = ip.Assign (p2pDevices);
// setup the STAs
stack.Install (sta);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (sta);
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
staDev = wifi.Install (wifiPhy, wifiMac, sta);
staInterface = ip.Assign (staDev);
//creating udp applications
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install(remoteHost.Get(0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (remoteInterface.GetAddress(1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install(sta.Get(0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// save everything in containers.
staNodes.push_back (sta);
apDevices.push_back (apDev);
apInterfaces.push_back (apInterface);
staDevices.push_back (staDev);
staInterfaces.push_back (staInterface);
wifiX += 20.0;
}
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
/* Address dest;
std::string protocol;
if (sendIp)
{
dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
protocol = "ns3::UdpSocketFactory";
}
else
{
PacketSocketAddress tmp;
tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
tmp.SetProtocol (0x807);
dest = tmp;
protocol = "ns3::PacketSocketFactory";
}
OnOffHelper onoff = OnOffHelper (protocol, dest);
onoff.SetConstantRate (DataRate ("500kb/s"));
ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (3.0));
wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);*/
if (writeMobility)
{
AsciiTraceHelper ascii;
MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob"));
}
AnimationInterface anim("edgecomp2.xml");
Simulator::Stop (Seconds (5.0));
Simulator::Run ();
Simulator::Destroy ();
}
I encountered this problem before but you could check this out here as follows.
Global Routing problem with wifi infrastructure mode
GlobalRouting does NOT work with Wi-Fi

UART STM32L0, Parity bit implementation

I am setting up communication via USART2 Asynchronous to receive my data. Configuration for receive the data is 9600/7bit/1-bit stop/Parity Even/Mode Rx/Tx. The implementation works fine when no parity is implemented. But the specification dictates that even parity should be supported.
If added the parity, I received any value.I do not understand where is the problem.
My configuration is with STMCubeMx for STM32L031K6 nucleo.
void MX_USART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_7B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT;
huart2.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
huart2.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(uartHandle->Instance==USART2)
{
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
/**USART2 GPIO Configuration
PA9 ------> USART2_TX
PA10 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* Peripheral interrupt init */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
}
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
if(uartHandle->Instance==USART2)
{
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
/**USART2 GPIO Configuration
PA9 ------> USART2_TX
PA10 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
/* Peripheral interrupt Deinit*/
HAL_NVIC_DisableIRQ(USART2_IRQn);
}
}
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
/*Configure GPIO pin : PB3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/*********************** interruption **********************/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART2) //current UART
{
Receive();
HAL_UART_Receive_IT(&huart2, Rx_data, 1);
}
}
/******************** Main ******************************/
int main(void)
{
HW_Init();
HAL_UART_Receive_IT(&huart2, Rx_data, 1);
while (1)
{
}
}
When using parity on STM32 series, you need to increase the UART_WORDLENGTH_7B to UART_WORDLENGTH_8B (or UART_WORDLENGTH_9B if you have 8 bits of data).
I just experienced the same problem myself recently. The HAL API should been better at this point...

Set color map in a StructuredGrid or PolyData in VTK?

I am trying to create a color map for PolyData whose points make up the structure of a nuclear reactor.It seems like every time I change color, the size of the cells change depending on the scalar value I assign to them. I just want a color map which shows interpolated color between the cells of my structure or even points.
This is the code that causes my color map to change the size of the cells.
#include <vtkFloatArray.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkLookupTable.h>
#include <vtkPointData.h>
#include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkGlyph3DMapper.h>
int main(){
vtkSmartPointer<vtkPoints> points=//points used to set deminsions of grid
vtkSmartPointer<vtkPoints>::New();
// cube source
vtkSmartPointer<vtkCubeSource> cube =
vtkSmartPointer<vtkCubeSource>::New();
cube->SetZLength(2);
//-----------------------------------------------
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
points->Allocate(3136);
for(int i=0;i<27;++i){
if(i!=0){i+=1;}
for(int j=4;j<12;++j){
points->InsertNextPoint(j, 0, (i));
}
for(int k=2;k<14;++k){
points->InsertNextPoint(k, 1, i);
}
for(int m=2;m<4;++m)
for(int l=1;l<15;++l){
points->InsertNextPoint(l, m, i);
}
for(int n=4;n<12;++n)
for(int p=0;p<16;++p){
points->InsertNextPoint(p, n, i);
}
for(int q=12;q<14;++q)
for(int r=1;r<15;++r){
points->InsertNextPoint(r, q, i);
}
for(int s=2;s<14;++s){
points->InsertNextPoint(s, 14, i);
}
for(int t=4;t<12;++t){
points->InsertNextPoint(t, 15, i);
}
}
//--------------------build scalor array--------------------------
vtkSmartPointer<vtkFloatArray> sarray=
vtkSmartPointer<vtkFloatArray>::New();
sarray->SetNumberOfValues(3136);
for(int i=0;i<3136;++i){
if(i<2000)
sarray->InsertValue(i,1);
else
sarray->InsertValue(i,10);
}
vtkSmartPointer<vtkLookupTable>cTable =
vtkSmartPointer<vtkLookupTable>::New();
int tableSize = 10;// not sure if I need this
cTable->SetNumberOfTableValues(tableSize);// not sure if I need this
cTable->Build();
//--------------------------------------------------------------------------------
polydata->SetPoints(points);
polydata->BuildCells();
polydata->GetPointData()->SetScalars(sarray);
//---------------------------------------------
vtkSmartPointer<vtkGlyph3DMapper> mapper =
vtkSmartPointer<vtkGlyph3DMapper>::New();
mapper->SetSourceConnection(cube->GetOutputPort());
#if VTK_MAJOR_VERSION <= 5
mapper->SetInputConnection(polydata->GetProducerPort());
#else
mapper->SetInputData(polydata);
#endif
mapper->Update();
mapper->SetScalarRange(1, 10);
mapper->SetLookupTable(cTable);
//-----------------------------------------------------------------
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetPointSize(3);
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}