{"id":1801,"date":"2023-02-17T11:11:45","date_gmt":"2023-02-17T19:11:45","guid":{"rendered":"https:\/\/wp.ece.uw.edu\/funlab\/?page_id=1801"},"modified":"2023-03-20T21:52:38","modified_gmt":"2023-03-21T04:52:38","slug":"wifi-lte-coexistence-cc","status":"publish","type":"page","link":"https:\/\/wp.ece.uw.edu\/funlab\/resources\/wifi-lte-coexistence-cc\/","title":{"rendered":"wifi-lte-coexistence.cc"},"content":{"rendered":"<p>wifi-lte-coexistence.cc:<\/p>\n<pre>#include \"ns3\/core-module.h\"\r\n#include \"ns3\/config-store-module.h\"\r\n#include \"ns3\/mobility-module.h\"\r\n#include \"ns3\/gnuplot.h\"\r\n#include \"ns3\/wifi-module.h\"\r\n#include \"ns3\/lte-module.h\"\r\n#include \"ns3\/network-module.h\"\r\n#include \"ns3\/internet-module.h\"\r\n#include \"ns3\/point-to-point-module.h\"\r\n#include \"ns3\/applications-module.h\"\r\n#include \"ns3\/spectrum-module.h\"\r\n#include \"ns3\/lte-wifi-coexistence-module.h\"\r\n#include \"ns3\/lte-spectrum-value-helper.h\"\r\n#include &lt;iostream&gt;\r\n#include &lt;iomanip&gt;\r\n#include &lt;sstream&gt;\r\n#include &lt;stdint.h&gt;\r\n\r\nNS_LOG_COMPONENT_DEFINE (\"Wifi11aLteDcBasic\");\r\n\r\nusing namespace ns3;\r\n\r\nstd::ofstream Pcolfile;\r\nstd::ofstream signalArrivalTraceFile;\r\nstd::ofstream cwTraceFile;\r\nstd::ofstream backoffTraceFile;\r\nstd::ofstream phyTxTraceFile;\r\nstd::ofstream macTxTraceFile;\r\nstd::ofstream socketRecvTraceFile;\r\nstd::vector&lt;uint32_t&gt; wifiPacketsReceived (100);\r\nstd::vector&lt;uint32_t&gt; wifiBytesReceived (100);\r\nstd::vector&lt;double&gt; wifiThroughputPerNode (100);\r\nstd::vector&lt;double&gt; wifiPacketsSent (100);\r\nstd::vector&lt;uint32_t&gt; ltePacketsReceived (100);\r\nstd::vector&lt;uint32_t&gt; lteBytesReceived (100);\r\nstd::vector&lt;double&gt; lteThroughputPerNode (100);\r\nstd::vector&lt;double&gt; ltePacketsSent (100);\r\ndouble progress;\r\n\/\/ Parse context strings of the form \"\/NodeList\/3\/DeviceList\/1\/Mac\/Assoc\"\r\n\/\/ to extract the NodeId\r\nuint32_t\r\nContextToNodeId1 (std::string context)\r\n{\r\n  std::string sub = context.substr (10);  \/\/ skip \"\/NodeList\/\"\r\n  uint32_t pos = sub.find (\"\/Device\");\r\n  NS_LOG_DEBUG (\"Found NodeId \" &lt;&lt; atoi (sub.substr (0, pos).c_str ()));\r\n  return atoi (sub.substr (0,pos).c_str ());\r\n}\r\n\r\nuint32_t pktSize = 100; \/\/1500\r\n\r\n\/\/ Function calls for tracing.\r\nvoid\r\nSignalArrivalTrace (std::string context, bool signalType, uint32_t senderNodeId, double rxPower, Time duration)\r\n{\r\n  signalArrivalTraceFile &lt;&lt; std::setprecision (6) &lt;&lt; std::fixed &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; (signalType ? \" wifi \" : \" lte \") &lt;&lt; senderNodeId &lt;&lt; \" \" &lt;&lt; rxPower &lt;&lt; \" \" &lt;&lt; duration.GetSeconds () &lt;&lt; std::endl;\r\n}\r\n\r\nvoid\r\nCwTrace (std::string context, uint32_t oldVal, uint32_t newVal)\r\n{\r\n  cwTraceFile &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; \" \" &lt;&lt; ContextToNodeId1 (context) &lt;&lt; \" \" &lt;&lt; newVal &lt;&lt; std::endl;\r\n}\r\n\r\nvoid\r\nBackoffTrace (std::string context, uint32_t newVal)\r\n{\r\n  backoffTraceFile &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; \" \" &lt;&lt; ContextToNodeId1 (context) &lt;&lt; \" \" &lt;&lt; newVal &lt;&lt; std::endl;\r\n}\r\n\r\nvoid\r\nLteSpectrumPhyTxTrace (std::string context, Ptr&lt;const PacketBurst&gt; pb)\r\n{\r\n  uint32_t nodeId = ContextToNodeId1 (context);\r\n  if (Simulator::Now () &gt;= Seconds (1))\r\n    {\r\n      ltePacketsSent[nodeId] += pb-&gt;GetNPackets ();\r\n    }\r\n\r\n}\r\n\r\nvoid\r\nPhyTxTrace (std::string context, Ptr&lt;const Packet&gt; p)\r\n{\r\n  phyTxTraceFile &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; \" \" &lt;&lt; ContextToNodeId1 (context) &lt;&lt; \" \" &lt;&lt; p-&gt;GetSize () &lt;&lt; std::endl;\r\n  uint32_t nodeId = ContextToNodeId1 (context);\r\n  if (p-&gt;GetSize () &gt; pktSize)\r\n    {\r\n      wifiPacketsSent[nodeId]++;\r\n    }\r\n}\r\n\r\nvoid\r\nMacTxTrace (std::string context, Ptr&lt;const Packet&gt; p)\r\n{\r\n  macTxTraceFile &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; \" \" &lt;&lt; ContextToNodeId1 (context) &lt;&lt; \" \" &lt;&lt; p-&gt;GetSize () &lt;&lt; std::endl;\r\n}\r\n\r\nvoid\r\nSocketRecvTrace (std::string context, Ptr&lt;const Packet&gt; p, const Address &amp;addr)\r\n{\r\n  socketRecvTraceFile &lt;&lt; Simulator::Now ().GetSeconds () &lt;&lt; \" \" &lt;&lt; ContextToNodeId1 (context) &lt;&lt; \" \" &lt;&lt; p-&gt;GetSize () &lt;&lt; std::endl;\r\n}\r\n\r\nvoid\r\nSocketRecvStats (std::string context, Ptr&lt;const Packet&gt; p, const Address &amp;addr)\r\n{\r\n  uint32_t nodeId = ContextToNodeId1 (context);\r\n  if (Simulator::Now () &gt;= Seconds (1))\r\n    {\r\n      wifiBytesReceived[nodeId] += p-&gt;GetSize ();\r\n      wifiPacketsReceived[nodeId]++;\r\n    }\r\n}\r\n\r\nvoid\r\nSinkRecvStats (std::string context, Ptr&lt;const Packet&gt; p, const Address &amp;addr)\r\n{\r\n  uint32_t nodeId = ContextToNodeId1 (context);\r\n  \/\/ Each packet is 1024 bytes UDP payload, but at L2, we need to add 8 + 20 header bytes to support throughput calculations at the LTE layer\r\n  \/\/std::cout&lt;&lt; \"  print packet size: \" &lt;&lt; p-&gt;GetSize () &lt;&lt; std::endl;\r\n  if (Simulator::Now () &gt;= Seconds (1))\r\n    {\r\n      lteBytesReceived[nodeId] += (p-&gt;GetSize () + 20 + 8);\r\n      ltePacketsReceived[nodeId]++;\r\n  }\r\n}\r\n\r\n\r\nvoid\r\nRestartCalc ()\r\n{\r\n  std::fill (wifiBytesReceived.begin (), wifiBytesReceived.end (), 0);\r\n  std::fill (wifiPacketsReceived.begin (), wifiPacketsReceived.end (), 0);\r\n  std::fill (wifiPacketsSent.begin (), wifiPacketsSent.end (), 0);\r\n  std::fill (lteBytesReceived.begin (), lteBytesReceived.end (), 0);\r\n  std::fill (ltePacketsReceived.begin (), ltePacketsReceived.end (), 0);\r\n  std::fill (ltePacketsSent.begin (), ltePacketsSent.end (), 0);\r\n}\r\n\r\nvoid\r\nShowProgress (void)\r\n{\r\n  std::cout &lt;&lt; \"  Progress to \" &lt;&lt; Simulator::Now ().As (Time::S) &lt;&lt; std::endl;\r\n  Simulator::Schedule (Seconds (progress), &amp;ShowProgress);\r\n}\r\n\r\nclass Experiment\r\n{\r\npublic:\r\n  Experiment ();\r\n  int Run (const WifiHelper &amp;wifi, uint32_t pktSize, uint32_t netSize, double delta, uint32_t gridWidth, double duration, bool tracing, double lteDutyCycle, bool useAbs, Time lteDutyCyclePeriod);\r\nprivate:\r\n};\r\n\r\nExperiment::Experiment ()\r\n{\r\n}\r\n\r\nint\r\nExperiment::Run (const WifiHelper &amp;wifi,\r\n                 uint32_t pktSize, uint32_t networkSize, double delta, uint32_t gridWidth, double duration, bool tracing, double lteDutyCycle, bool useAbs, Time lteDutyCyclePeriod)\r\n{\r\n  bool saveAttributeConfig = false;\r\n\r\n  NodeContainer c;\r\n  c.Create (networkSize);\r\n\r\n  Ptr&lt;MultiModelSpectrumChannel&gt; spectrumChannel;\r\n  Ptr&lt;LteHelper&gt; lteHelper;\r\n  Ptr&lt;PointToPointEpcHelper&gt; epcHelper;\r\n  Ptr&lt;Node&gt; pgw;\r\n  Ptr&lt;Node&gt; remoteHost;\r\n  NodeContainer remoteHostContainer;\r\n  NodeContainer ueNodes;\r\n  NodeContainer enbNodes;\r\n  ApplicationContainer clientApps;\r\n  ApplicationContainer serverApps;\r\n\r\n  lteHelper = CreateObject&lt;LteHelper&gt; ();\r\n  epcHelper = CreateObject&lt;PointToPointEpcHelper&gt; ();\r\n  lteHelper-&gt;SetEpcHelper (epcHelper);\r\n  lteHelper-&gt;SetEnbDeviceAttribute (\"DlBandwidth\", UintegerValue (100)); \/\/ 20MHz for 100 RU\r\n  lteHelper-&gt;SetEnbDeviceAttribute (\"DlEarfcn\", UintegerValue (255444));  \/\/ for 5180 MHz fc\r\n  pgw = epcHelper-&gt;GetPgwNode ();\r\n  remoteHostContainer.Create (1);\r\n  remoteHost = remoteHostContainer.Get (0);\r\n  InternetStackHelper internet;\r\n  internet.Install (remoteHostContainer);\r\n\r\n  \/\/ Create the Internet\r\n  PointToPointHelper p2ph;\r\n  p2ph.SetDeviceAttribute (\"DataRate\", DataRateValue (DataRate (\"100Gb\/s\")));\r\n  p2ph.SetDeviceAttribute (\"Mtu\", UintegerValue (1500));\r\n  p2ph.SetChannelAttribute (\"Delay\", TimeValue (Seconds (0.00010)));\r\n  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);\r\n  Ipv4AddressHelper ipv4h;\r\n  ipv4h.SetBase (\"1.0.0.0\", \"255.0.0.0\");\r\n  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);\r\n\r\n  Ipv4StaticRoutingHelper ipv4RoutingHelper;\r\n  Ptr&lt;Ipv4StaticRouting&gt; remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost-&gt;GetObject&lt;Ipv4&gt; ());\r\n  remoteHostStaticRouting-&gt;AddNetworkRouteTo (Ipv4Address (\"7.0.0.0\"), Ipv4Mask (\"255.0.0.0\"), 1);\r\n\r\n  enbNodes.Create (1);\r\n  ueNodes.Create (1);\r\n\r\n  \/\/ Install Mobility Model\r\n  Ptr&lt;ListPositionAllocator&gt; positionAlloc = CreateObject&lt;ListPositionAllocator&gt; ();\r\n  for (uint16_t i = 0; i &lt; 2; i++)\r\n    {\r\n      positionAlloc-&gt;Add (Vector (0.1 * i, 0, 0));\r\n    }\r\n  MobilityHelper mobility;\r\n  mobility.SetMobilityModel (\"ns3::ConstantPositionMobilityModel\");\r\n  mobility.SetPositionAllocator (positionAlloc);\r\n  mobility.Install (enbNodes);\r\n  mobility.Install (ueNodes);\r\n\r\n  \/\/ Install LTE Devices to the nodes\r\n  NetDeviceContainer enbLteDevs = lteHelper-&gt;InstallEnbDevice (enbNodes);\r\n  NetDeviceContainer ueLteDevs = lteHelper-&gt;InstallUeDevice (ueNodes);\r\n\r\n  \/\/ Install the IP stack on the UEs\r\n  internet.Install (ueNodes);\r\n  Ipv4InterfaceContainer ueIpIface;\r\n  ueIpIface = epcHelper-&gt;AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));\r\n  \/\/ Assign IP address to UEs, and install applications\r\n  for (uint32_t u = 0; u &lt; ueNodes.GetN (); ++u)\r\n    {\r\n      Ptr&lt;Node&gt; ueNode = ueNodes.Get (u);\r\n      \/\/ Set the default gateway for the UE\r\n      Ptr&lt;Ipv4StaticRouting&gt; ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode-&gt;GetObject&lt;Ipv4&gt; ());\r\n      ueStaticRouting-&gt;SetDefaultRoute (epcHelper-&gt;GetUeDefaultGatewayAddress (), 1);\r\n    }\r\n\r\n  \/\/ Attach one UE per eNodeB\r\n  for (uint16_t i = 0; i &lt; ueLteDevs.GetN (); i++)\r\n    {\r\n      lteHelper-&gt;Attach (ueLteDevs.Get (i), enbLteDevs.Get (i));\r\n      \/\/ side effect: the default EPS bearer will be activated\r\n    }\r\n\r\n  \/\/ Obtain channel pointer from LTE, for use in Wi-Fi\r\n  Ptr&lt;LteEnbNetDevice&gt; lteEnbNetDevice = DynamicCast&lt;LteEnbNetDevice&gt; (enbLteDevs.Get (0));\r\n  NS_ASSERT (lteEnbNetDevice);\r\n  Ptr&lt;SpectrumChannel&gt; downlinkSpectrumChannel = lteEnbNetDevice-&gt;GetPhy (0)-&gt;GetDownlinkSpectrumPhy ()-&gt;GetChannel ();\r\n  spectrumChannel = DynamicCast&lt;MultiModelSpectrumChannel&gt; (downlinkSpectrumChannel);\r\n  NS_ASSERT (spectrumChannel);\r\n\r\n  if (useAbs)\r\n    {\r\n      \/\/ determine the LTE Almost Blank Subframe (ABS) pattern that will implement the desired duty cycle\r\n      NS_ABORT_MSG_UNLESS (lteDutyCycle &gt;= 0 &amp;&amp; lteDutyCycle &lt;= 1, \"lteDutyCycle must be between 1 and 0\");\r\n      std::bitset&lt;40&gt; absPattern;\r\n      \/\/ need at least two regular subframes for MIB and SIB1\r\n      absPattern[0] = 0;\r\n      absPattern[35] = 0;\r\n      uint32_t regularSubframes = 2;\r\n      int32_t subframe = 39;\r\n      while ((regularSubframes &lt; 40) &amp;&amp; (regularSubframes \/ 40.0 &lt; lteDutyCycle))\r\n        {\r\n          if (subframe != 0 &amp;&amp; subframe != 35)\r\n            {\r\n              absPattern[subframe] = 0;\r\n              ++regularSubframes;\r\n            }\r\n          --subframe;\r\n        }\r\n      while (subframe &gt;= 0)\r\n        {\r\n          if (subframe != 0 &amp;&amp; subframe != 35)\r\n            {\r\n              absPattern[subframe] = 1;\r\n            }\r\n          --subframe;\r\n        }\r\n      double actualLteDutyCycle = regularSubframes \/ 40.0;\r\n      std::cout &lt;&lt; \"LTE ABS-based duty cycle: requested \" &lt;&lt; lteDutyCycle &lt;&lt; \", actual \" &lt;&lt; actualLteDutyCycle &lt;&lt; \", ABS pattern \" &lt;&lt; absPattern &lt;&lt; std::endl;\r\n      lteEnbNetDevice-&gt;GetRrc ()-&gt;SetAbsPattern (absPattern);\r\n    }\r\n  else\r\n    {\r\n      \/\/ Multiplying Time object directly by double value does not work\r\n      Time onDuration = Seconds (lteDutyCyclePeriod.GetSeconds () * lteDutyCycle);\r\n      std::cout &lt;&lt; \"LTE duty cycle access manager: requested \" &lt;&lt; lteDutyCycle &lt;&lt; \", period \" &lt;&lt; lteDutyCyclePeriod.GetMilliSeconds () &lt;&lt; \" ms \" &lt;&lt; std::fixed &lt;&lt; std::setprecision (2) &lt;&lt; \" on duration \" &lt;&lt; onDuration.GetSeconds () * 1000 &lt;&lt; \" ms\" &lt;&lt; std::endl;\r\n      Ptr&lt;DutyCycleAccessManager&gt; dutyCycleAccessManager = CreateObject&lt;DutyCycleAccessManager&gt; ();\r\n      dutyCycleAccessManager-&gt;SetDutyCyclePeriod (lteDutyCyclePeriod);\r\n      dutyCycleAccessManager-&gt;SetOnDuration (onDuration);\r\n      lteEnbNetDevice-&gt;GetPhy ()-&gt;SetChannelAccessManager (dutyCycleAccessManager);\r\n    }\r\n\r\n  \/\/ Install and start applications on UEs and remote host\r\n  uint16_t dlPort = 1234;\r\n  uint16_t ulPort = 2000;\r\n  uint16_t otherPort = 3000;\r\n  for (uint32_t u = 0; u &lt; ueNodes.GetN (); ++u)\r\n    {\r\n      ++ulPort;\r\n      ++otherPort;\r\n      PacketSinkHelper dlPacketSinkHelper (\"ns3::UdpSocketFactory\", InetSocketAddress (Ipv4Address::GetAny (), dlPort));\r\n      PacketSinkHelper ulPacketSinkHelper (\"ns3::UdpSocketFactory\", InetSocketAddress (Ipv4Address::GetAny (), ulPort));\r\n      PacketSinkHelper packetSinkHelper (\"ns3::UdpSocketFactory\", InetSocketAddress (Ipv4Address::GetAny (), otherPort));\r\n      serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u)));\r\n      serverApps.Add (ulPacketSinkHelper.Install (remoteHost));\r\n      serverApps.Add (packetSinkHelper.Install (ueNodes.Get (u)));\r\n\r\n      UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort);\r\n\r\n      dlClient.SetAttribute (\"Interval\", TimeValue (MicroSeconds (100)));\r\n      dlClient.SetAttribute (\"MaxPackets\", UintegerValue (UINT32_MAX));\r\n      clientApps.Add (dlClient.Install (remoteHost));\r\n\r\n    }\r\n\t\r\n  serverApps.Start (Seconds (0.01));\r\n  clientApps.Start (Seconds (0.01));\r\n  \/\/ p2ph.EnablePcapAll(\"my-lte\");\r\n\r\n  SpectrumWifiPhyHelper spectrumPhy = SpectrumWifiPhyHelper::Default ();\r\n  spectrumPhy.SetChannel (spectrumChannel);\r\n  spectrumPhy.Set (\"Frequency\", UintegerValue (5180)); \/\/ channel 36 at 20 MHz\r\n  spectrumPhy.Set (\"TxPowerStart\", DoubleValue (1));\r\n  spectrumPhy.Set (\"TxPowerEnd\", DoubleValue (1));\r\n\r\n  WifiMacHelper mac;\r\n  mac.SetType (\"ns3::AdhocWifiMac\");\r\n  NetDeviceContainer devices = wifi.Install (spectrumPhy, mac, c);\r\n\r\n  mobility.SetPositionAllocator (\"ns3::GridPositionAllocator\",\r\n                                 \"MinX\", DoubleValue (0.0),\r\n                                 \"MinY\", DoubleValue (0.0),\r\n                                 \"DeltaX\", DoubleValue (delta),\r\n                                 \"DeltaY\", DoubleValue (delta),\r\n                                 \"GridWidth\", UintegerValue (gridWidth),\r\n                                 \"LayoutType\", StringValue (\"RowFirst\"));\r\n  mobility.SetMobilityModel (\"ns3::ConstantPositionMobilityModel\");\r\n  mobility.Install (c);\r\n\r\n  PacketSocketHelper packetSocket;\r\n  packetSocket.Install (c);\r\n\r\n  uint32_t nNodes = c.GetN ();\r\n  ApplicationContainer apps;\r\n  TypeId tid = TypeId::LookupByName (\"ns3::UdpSocketFactory\");\r\n  Ptr&lt;UniformRandomVariable&gt; startTime = CreateObject&lt;UniformRandomVariable&gt; ();\r\n  startTime-&gt;SetAttribute (\"Max\", DoubleValue (200.0));\r\n  for (uint32_t i = 0; i &lt; nNodes; ++i)\r\n    {\r\n      uint32_t j = (i + 1) % nNodes;\r\n      PacketSocketAddress socketAddr;\r\n      socketAddr.SetSingleDevice (devices.Get (i)-&gt;GetIfIndex ());\r\n      socketAddr.SetPhysicalAddress (devices.Get (j)-&gt;GetAddress ());\r\n      socketAddr.SetProtocol (1);\r\n\r\n      Ptr&lt;PacketSocketClient&gt; client = CreateObject&lt;PacketSocketClient&gt; ();\r\n      client-&gt;SetRemote (socketAddr);\r\n      c.Get (i)-&gt;AddApplication (client);\r\n      client-&gt;SetAttribute (\"PacketSize\", UintegerValue (pktSize));\r\n      client-&gt;SetAttribute (\"MaxPackets\", UintegerValue (0));\r\n      client-&gt;SetAttribute (\"Interval\", TimeValue (MicroSeconds (100)));\r\n\r\n      Ptr&lt;PacketSocketServer&gt; server = CreateObject&lt;PacketSocketServer&gt; ();\r\n      server-&gt;SetLocal (socketAddr);\r\n      c.Get (j)-&gt;AddApplication (server);\r\n    }\r\n\r\n  \/\/ Log Wifi packet receptions\r\n  Config::Connect (\"\/NodeList\/*\/$ns3::Node\/ApplicationList\/*\/$ns3::PacketSocketServer\/Rx\", MakeCallback (&amp;SocketRecvStats));\r\n\r\n  \/\/ Log LTE packet transmissions\r\n  Config::Connect (\"\/NodeList\/*\/DeviceList\/*\/$ns3::LteEnbNetDevice\/ComponentCarrierMap\/*\/LteEnbPhy\/DlSpectrumPhy\/TxStart\", MakeCallback (&amp;LteSpectrumPhyTxTrace));\r\n\r\n\r\n  \/\/ Log LTE packet receptions\r\n  std::ostringstream oss;\r\n  oss &lt;&lt; \"\/NodeList\/\" &lt;&lt; nNodes+3 &lt;&lt; \"\/$ns3::Node\/ApplicationList\/*\/$ns3::PacketSink\/Rx\";\r\n  std::string var = oss.str();\r\n  Config::Connect (var, MakeCallback (&amp;SinkRecvStats));\r\n\r\n  \/\/ Trace Phy Tx start events\r\n  Config::Connect (\"\/NodeList\/*\/DeviceList\/*\/$ns3::WifiNetDevice\/Phy\/$ns3::WifiPhy\/PhyTxBegin\", MakeCallback (&amp;PhyTxTrace));\r\n  \r\n  if (tracing)\r\n    {\r\n      \/\/ Trace CW evolution\r\n      Config::Connect (\"\/NodeList\/*\/DeviceList\/*\/$ns3::WifiNetDevice\/Mac\/$ns3::AdhocWifiMac\/Txop\/CwTrace\", MakeCallback (&amp;CwTrace));\r\n\r\n      \/\/ Trace backoff evolution\r\n      Config::Connect (\"\/NodeList\/*\/DeviceList\/*\/$ns3::WifiNetDevice\/Mac\/$ns3::AdhocWifiMac\/Txop\/BackoffTrace\", MakeCallback (&amp;BackoffTrace));\r\n\r\n      \/\/ Trace packet arrivals to the Wifi device\r\n      Config::Connect (\"\/NodeList\/*\/DeviceList\/*\/$ns3::WifiNetDevice\/Mac\/$ns3::AdhocWifiMac\/MacTx\", MakeCallback (&amp;MacTxTrace));\r\n\r\n      \/\/ Trace packet receptions\r\n      Config::Connect (\"\/NodeList\/*\/$ns3::Node\/ApplicationList\/*\/$ns3::PacketSocketServer\/Rx\", MakeCallback (&amp;SocketRecvTrace));\r\n\r\n      \/\/ Trace signal arrivals at node 0\r\n      Config::Connect (\"\/NodeList\/0\/DeviceList\/0\/$ns3::WifiNetDevice\/Phy\/$ns3::SpectrumWifiPhy\/SignalArrival\", MakeCallback (&amp;SignalArrivalTrace));\r\n    }\r\n  Simulator::Schedule (Seconds (5.0), &amp;RestartCalc);\r\n  Simulator::Stop (Seconds (duration));\r\n\r\n  if (saveAttributeConfig)\r\n    {\r\n      \/\/ Output config store to txt format\r\n      Config::SetDefault (\"ns3::ConfigStore::Filename\", StringValue (\"wifi-11a-lte-dc-attributes.txt\"));\r\n      Config::SetDefault (\"ns3::ConfigStore::FileFormat\", StringValue (\"RawText\"));\r\n      Config::SetDefault (\"ns3::ConfigStore::Mode\", StringValue (\"Save\"));\r\n      ConfigStore outputConfig2;\r\n      outputConfig2.ConfigureAttributes ();\r\n      std::cout &lt;&lt; \"Exiting afer writing wifi-11a-lte-dc-attributes.txt\" &lt;&lt; std::endl;\r\n      exit (0);\r\n    }\r\n\r\n  if (progress)\r\n    {\r\n      Simulator::Schedule (Seconds (progress), &amp;ShowProgress);\r\n    }\r\n  Simulator::Run ();\r\n  Simulator::Destroy ();\r\n  if (tracing)\r\n    {\r\n      signalArrivalTraceFile.flush ();\r\n      cwTraceFile.flush ();\r\n      backoffTraceFile.flush ();\r\n      phyTxTraceFile.flush ();\r\n      macTxTraceFile.flush ();\r\n      socketRecvTraceFile.flush ();\r\n    }\r\n  return 0;\r\n}\r\n\r\nint main (int argc, char *argv[])\r\n{\r\n  uint32_t verbose = 0;\r\n  bool tracing = false;\r\n  progress = 10;\r\n  double duration = 10;\r\n  uint32_t netSize = 2;\r\n  \/\/ uint32_t pktSize = 1500; \/\/1500\r\n  double delta = 0.001;\r\n  uint32_t trials = 3;\r\n  uint32_t gridWidth = 10;\r\n  double lteDutyCycle = 1;\r\n  bool useAbs = false;\r\n  Time lteDutyCyclePeriod = MilliSeconds (10);\r\n\r\n  double P_col = 0;\r\n\r\n  \/\/ disable fragmentation\r\n  Config::SetDefault (\"ns3::WifiRemoteStationManager::FragmentationThreshold\", StringValue (\"22000\"));\r\n  Config::SetDefault (\"ns3::WifiRemoteStationManager::RtsCtsThreshold\", StringValue (\"22000\"));\r\n  \/\/ Disable short retransmission failure (make retransmissions persistent)\r\n  Config::SetDefault (\"ns3::WifiRemoteStationManager::MaxSlrc\", UintegerValue (8));\r\n\r\n  \/\/ Configure start time of access manager\r\n  Config::SetDefault (\"ns3::LteEnbPhy::ChannelAccessManagerStartTime\", TimeValue (Seconds (1)));\r\n\r\n  CommandLine cmd;\r\n  cmd.AddValue (\"verbose\", \"Show log output (default is 0: no log)\", verbose);\r\n  cmd.AddValue (\"useAbs\",  \"Use ABS mode of duty cycling (40 ms cycle)\", useAbs);\r\n  cmd.AddValue (\"lteDutyCycle\", \"LTE duty cycle fraction of time (0 to 1)\", lteDutyCycle);\r\n  cmd.AddValue (\"lteDutyCyclePeriod\", \"LTE duty cycle period\", lteDutyCyclePeriod);\r\n  cmd.AddValue (\"tracing\", \"Generate trace files\", tracing);\r\n  cmd.AddValue (\"netSize\", \"The maximum network size\", netSize);\r\n  cmd.AddValue (\"pktSize\", \"The frame size\", pktSize);\r\n  cmd.AddValue (\"trials\", \"The maximal number of runs per network size\", trials);\r\n  cmd.AddValue (\"delta\", \"The delta offset in grid topology\", delta);\r\n  cmd.AddValue (\"gridWidth\", \"The width of the grid\", gridWidth);\r\n  cmd.AddValue (\"duration\", \"Time duration for each trial (seconds)\", duration);\r\n  cmd.AddValue (\"showProgress\", \"time interval (sec) for showing execution progress; zero to disable\", progress);\r\n  cmd.Parse (argc, argv);\r\n\r\n  if (tracing)\r\n    {\r\n      signalArrivalTraceFile.open (\"wifi-11a-lte-dc-signal-trace.out\");\r\n      cwTraceFile.open (\"wifi-11a-lte-dc-cw-trace.out\");\r\n      backoffTraceFile.open (\"wifi-11a-lte-dc-backoff-trace.out\");\r\n      phyTxTraceFile.open (\"wifi-11a-lte-dc-phy-tx-trace.out\");\r\n      macTxTraceFile.open (\"wifi-11a-lte-dc-mac-tx-trace.out\");\r\n      socketRecvTraceFile.open (\"wifi-11a-lte-dc-socket-recv-trace.out\");\r\n    }\r\n  Pcolfile.open (\"OutPutFile.out\");\r\n  if (verbose == 1)\r\n    {\r\n      LogComponentEnable (\"Wifi11aLteDcBasic\", LOG_LEVEL_ALL);\r\n    }\r\n  else if (verbose == 2)\r\n    {\r\n      LogComponentEnable (\"Wifi11aLteDcBasic\", LOG_LEVEL_ALL);\r\n      LogComponentEnable (\"DcfManager\", LOG_LEVEL_ALL);\r\n      LogComponentEnable (\"Txop\", LOG_LEVEL_ALL);\r\n      LogComponentEnable (\"QosTxop\", LOG_LEVEL_ALL);\r\n    }\r\n  else if (verbose == 3)\r\n    {\r\n      LogComponentEnable (\"Wifi11aLteDcBasic\", LOG_LEVEL_ALL);\r\n      WifiHelper h;\r\n      h.EnableLogComponents ();\r\n    }\r\n\r\n  std::stringstream ss;\r\n  ss &lt;&lt; \"wifi-11a-lte-dc-\" &lt;&lt; netSize &lt;&lt; \"-p-\" &lt;&lt; pktSize &lt;&lt; \"-throughput.plt\";\r\n  std::ofstream netSizeThroughputPlot (ss.str ().c_str ());\r\n  ss.str (\"\");\r\n  ss &lt;&lt; \"wifi-11a-lte-dc-\" &lt;&lt; netSize &lt;&lt; \"-p-\" &lt;&lt; pktSize &lt;&lt; \"-throughput.eps\";\r\n  Gnuplot gnuplot = Gnuplot (ss.str ());\r\n\r\n  WifiHelper wifi;\r\n  wifi.SetStandard (WIFI_PHY_STANDARD_80211a);\r\n\r\n  NS_LOG_DEBUG (\"6\");\r\n  Experiment experiment;\r\n  wifi.SetRemoteStationManager (\"ns3::ConstantRateWifiManager\",\r\n                                \"DataMode\", StringValue (\"OfdmRate6Mbps\")); \/\/ OfdmRate12Mbps \/\/ OfdmRate54Mbps\r\n\r\n  \r\n  double mean_t, throughput;\r\n  double mean_pcol;\r\n\r\n  for (uint32_t p_inc = 50; p_inc &lt;= 1950 ; p_inc += 50)\r\n    {\r\n      pktSize = 50 + p_inc;\r\n      mean_t = 0;\r\n      mean_pcol=0;\r\n\r\n      for (uint32_t run_index = 1; run_index &lt;= trials; run_index++)\r\n        {\r\n\r\n          std::fill (wifiBytesReceived.begin (), wifiBytesReceived.end (), 0);\r\n          std::fill (wifiPacketsReceived.begin (), wifiPacketsReceived.end (), 0);\r\n          std::fill (lteBytesReceived.begin (), lteBytesReceived.end (), 0);\r\n          std::fill (ltePacketsReceived.begin (), ltePacketsReceived.end (), 0);\r\n          throughput = 0;\r\n\r\n          std::cout &lt;&lt; \"Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; pktSize &lt;&lt; \" packetsize \" &lt;&lt; std::endl;\r\n          if (tracing)\r\n            {\r\n              cwTraceFile &lt;&lt; \"# Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; netSize &lt;&lt; \" nodes\" &lt;&lt; std::endl;\r\n              backoffTraceFile &lt;&lt; \"# Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; netSize &lt;&lt; \" nodes\" &lt;&lt; std::endl;\r\n              phyTxTraceFile &lt;&lt; \"# Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; netSize &lt;&lt; \" nodes\" &lt;&lt; std::endl;\r\n              macTxTraceFile &lt;&lt; \"# Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; netSize &lt;&lt; \" nodes\" &lt;&lt; std::endl;\r\n              socketRecvTraceFile &lt;&lt; \"# Trial \" &lt;&lt; run_index &lt;&lt; \" of \" &lt;&lt; trials &lt;&lt; \"; 6 Mb\/s for \" &lt;&lt; netSize &lt;&lt; \" nodes\" &lt;&lt; std::endl;\r\n            }\r\n          experiment.Run (wifi, pktSize, netSize, delta, gridWidth, duration, tracing, lteDutyCycle, useAbs, lteDutyCyclePeriod);\r\n          double avg;\r\n          for (uint32_t k = 0; k &lt; netSize; k++)\r\n            {\r\n              wifiThroughputPerNode[k] = (double)(wifiBytesReceived[k]* 8) \/ 1000 \/ 1000 \/ 5;  \/\/ for 100 seconds\r\n              std::cout &lt;&lt; \"Node \" &lt;&lt; k &lt;&lt; \"; wifi throughput \" &lt;&lt; wifiThroughputPerNode[k] &lt;&lt; std::endl;\r\n              throughput += wifiThroughputPerNode[k];\r\n              if (wifiPacketsSent[k] &gt; 0)\r\n                {\r\n                  P_col += (wifiPacketsSent[k] - wifiPacketsReceived[(k + 1) % netSize]) \/ wifiPacketsSent[k];\r\n                }\r\n              std::cout &lt;&lt; P_col &lt;&lt; std::endl;\r\n              avg += P_col;\r\n              P_col = 0;\r\n            }\r\n          \/\/ For network size 'n', the receive sink will be node 'n+3'\r\n          \/\/std::cout &lt;&lt; \"lte Packets: \" &lt;&lt; lteBytesReceived[netSize+3] &lt;&lt;std::endl;\r\n          double lteThroughput = (double)(lteBytesReceived[netSize+3]* 8) \/ 1000 \/ 1000 \/ 5 ;\r\n          std::cout &lt;&lt; \"P collision Avg \" &lt;&lt; avg \/ netSize &lt;&lt; std::endl;\r\n          std::cout &lt;&lt; \"Total wifi throughput \" &lt;&lt; throughput &lt;&lt; std::endl;\r\n          std::cout &lt;&lt; \"Total LTE throughput \" &lt;&lt; lteThroughput &lt;&lt; std::endl;\r\n         \r\n          mean_t += throughput;\r\n          mean_pcol += avg \/ netSize;\r\n          avg = 0;\r\n        }\r\n      mean_t = mean_t \/ trials;\r\n      mean_pcol = mean_pcol \/ trials;\r\n\r\n      Pcolfile &lt;&lt; pktSize &lt;&lt; \", \" &lt;&lt; mean_t &lt;&lt; \", \" &lt;&lt; mean_pcol&lt;&lt; std::endl;\r\n    }\r\n\r\n  Pcolfile.close ();\r\n  \r\n  if (tracing)\r\n    {\r\n      signalArrivalTraceFile.close ();\r\n      cwTraceFile.close ();\r\n      backoffTraceFile.close ();\r\n      phyTxTraceFile.close ();\r\n      macTxTraceFile.close ();\r\n      socketRecvTraceFile.close ();\r\n    }\r\n  return 0;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>wifi-lte-coexistence.cc: #include &#8220;ns3\/core-module.h&#8221; #include &#8220;ns3\/config-store-module.h&#8221; #include &#8220;ns3\/mobility-module.h&#8221; #include &#8220;ns3\/gnuplot.h&#8221; #include &#8220;ns3\/wifi-module.h&#8221; #include &#8220;ns3\/lte-module.h&#8221; #include &#8220;ns3\/network-module.h&#8221; #include &#8220;ns3\/internet-module.h&#8221; #include &#8220;ns3\/point-to-point-module.h&#8221; #include &#8220;ns3\/applications-module.h&#8221; #include &#8220;ns3\/spectrum-module.h&#8221; #include &#8220;ns3\/lte-wifi-coexistence-module.h&#8221; #include &#8220;ns3\/lte-spectrum-value-helper.h&#8221; #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;sstream&gt; #include &lt;stdint.h&gt; NS_LOG_COMPONENT_DEFINE (&#8220;Wifi11aLteDcBasic&#8221;); using namespace ns3; std::ofstream Pcolfile; std::ofstream signalArrivalTraceFile; std::ofstream cwTraceFile; std::ofstream backoffTraceFile; std::ofstream phyTxTraceFile; std::ofstream macTxTraceFile; std::ofstream socketRecvTraceFile; std::vector&lt;uint32_t&gt; &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/wp.ece.uw.edu\/funlab\/resources\/wifi-lte-coexistence-cc\/\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":15,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"tags":[],"class_list":["post-1801","page","type-page","status-publish","hentry","nodate","item-wrap"],"_links":{"self":[{"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/pages\/1801","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/comments?post=1801"}],"version-history":[{"count":2,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/pages\/1801\/revisions"}],"predecessor-version":[{"id":1804,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/pages\/1801\/revisions\/1804"}],"up":[{"embeddable":true,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/pages\/15"}],"wp:attachment":[{"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/media?parent=1801"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.ece.uw.edu\/funlab\/wp-json\/wp\/v2\/tags?post=1801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}