Guest User

Untitled

a guest
Sep 15th, 2019
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 as
  5. * published by the Free Software Foundation;
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16.  
  17. #include "ns3/core-module.h"
  18. #include "ns3/point-to-point-module.h"
  19. #include "ns3/network-module.h"
  20. #include "ns3/applications-module.h"
  21.  
  22. #include "ns3/mobility-module.h"
  23. #include "ns3/mobility-model.h"
  24. #include "ns3/csma-module.h"
  25. #include "ns3/propagation-loss-model.h"
  26. #include "ns3/internet-module.h"
  27. #include "ns3/propagation-delay-model.h"
  28. #include "ns3/wifi-mac-helper.h"
  29. #include "ns3/yans-wifi-channel.h"
  30. #include "ns3/yans-wifi-helper.h"
  31. #include <iostream>
  32. #include "ns3/cost231-propagation-loss-model.h"
  33.  
  34.  
  35. // Default Network Topology
  36. //
  37. // Wifi 10.1.1.0
  38. //
  39. // * *
  40. // | |
  41. // n0(transm) n1(receiver)
  42.  
  43.  
  44.  
  45.  
  46. using namespace ns3;
  47.  
  48.  
  49.  
  50. NS_LOG_COMPONENT_DEFINE ("LAB1");
  51.  
  52.  
  53. int
  54. main (int argc, char *argv[])
  55. {
  56. bool verbose = true;
  57. uint32_t nWifi = 2;
  58.  
  59. CommandLine cmd;
  60. cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
  61. cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
  62. cmd.Parse (argc,argv);
  63.  
  64. if (nWifi > 18)
  65. {
  66. std::cout << "Number of wifi nodes " << nWifi <<
  67. " specified exceeds the mobility bounding box" << std::endl;
  68. exit (1);
  69. }
  70.  
  71. if (verbose)
  72. {
  73. LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
  74. LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
  75. }
  76.  
  77. /////////////////////////////Nodes/////////////////////////////
  78. NodeContainer wifiStaNodes;
  79. wifiStaNodes.Create (nWifi);
  80.  
  81.  
  82. /////////////////////////////Wi-Fi part/////////////////////////////
  83.  
  84. Ptr<YansWifiChannel> channel = CreateObject <YansWifiChannel> (); //create a pointer for channel object
  85. Ptr<Cost231PropagationLossModel> lossModel = CreateObject<Cost231PropagationLossModel> (); //create a pointer for propagation loss model
  86. channel->SetPropagationLossModel (lossModel); // install propagation loss model
  87. channel->SetPropagationDelayModel (CreateObject <ConstantSpeedPropagationDelayModel> ()); // install propagation delay model
  88.  
  89. Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
  90. Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
  91.  
  92.  
  93. YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
  94. phy.SetChannel (channel);
  95. phy.Set("TxPowerEnd", DoubleValue(16));
  96. phy.Set("TxPowerStart", DoubleValue(16));
  97. phy.Set("RxSensitivity", DoubleValue(-80));
  98. // phy.Set("CcaMode1Threshold", DoubleValue(-99));
  99. phy.Set("ChannelNumber", UintegerValue(7));
  100. phy.Set("RxGain", DoubleValue(0));
  101. phy.Set("TxGain", DoubleValue(0));
  102.  
  103.  
  104.  
  105. WifiHelper wifi = WifiHelper();
  106. wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
  107. // wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue ("DsssRate11Mbps"), "ControlMode",StringValue ("DsssRate11Mbps"), "RtsCtsThreshold", UintegerValue(3000));
  108. // wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",StringValue ("OfdmRate54Mbps"), "ControlMode",StringValue ("OfdmRate54Mbps"), "RtsCtsThreshold", UintegerValue(3000));
  109.  
  110. ///////////////////////////////////////////////////////////c
  111. wifi.SetRemoteStationManager ("ns3::ArfWifiManager", "SuccessThreshold",StringValue ("1") );
  112. //////////////////////////////////////////////////////////
  113.  
  114. WifiMacHelper mac = WifiMacHelper();
  115. mac.SetType ("ns3::AdhocWifiMac");
  116.  
  117. /////////////////////////////Devices/////////////////////////////
  118. NetDeviceContainer staDevices;
  119. staDevices = wifi.Install (phy, mac, wifiStaNodes);
  120.  
  121. /////////////////////////////Deployment/////////////////////////////
  122. MobilityHelper mobility;
  123. Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
  124. positionAlloc->Add (Vector (0.0, 0.0, 1.0));
  125. positionAlloc->Add (Vector (43.1, 0.0, 1.0)); //251.1 for two way ground propagation model
  126.  
  127. mobility.SetPositionAllocator (positionAlloc);
  128. mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  129. mobility.Install (wifiStaNodes);
  130.  
  131. /////////////////////////////Stack of protocols/////////////////////////////
  132.  
  133. InternetStackHelper stack;
  134. stack.Install (wifiStaNodes);
  135.  
  136. Ipv4AddressHelper address;
  137.  
  138. /////////////////////////////Ip addresation/////////////////////////////
  139. address.SetBase ("10.1.1.0", "255.255.255.0");
  140. Ipv4InterfaceContainer wifiInterfaces;
  141. wifiInterfaces = address.Assign (staDevices);
  142.  
  143.  
  144. /////////////////////////////Application part/////////////////////////////
  145. UdpEchoServerHelper echoServer (9);
  146.  
  147. ApplicationContainer serverApps = echoServer.Install (wifiStaNodes.Get (nWifi-1));
  148. serverApps.Start (Seconds (1.0));
  149. serverApps.Stop (Seconds (30.0));
  150.  
  151. UdpEchoClientHelper echoClient (wifiInterfaces.GetAddress (nWifi-1), 9);
  152. echoClient.SetAttribute ("MaxPackets", UintegerValue (15));
  153. echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
  154. echoClient.SetAttribute ("PacketSize", UintegerValue (1000));
  155.  
  156. ApplicationContainer clientApps = echoClient.Install (wifiStaNodes.Get (0));
  157. clientApps.Start (Seconds (2.0));
  158. clientApps.Stop (Seconds (20.0));
  159.  
  160.  
  161. Ptr<MobilityModel> mobil = wifiStaNodes.Get(0)->GetObject<MobilityModel> ();
  162. Ptr<MobilityModel> mobil2 = wifiStaNodes.Get(1)->GetObject<MobilityModel> ();
  163.  
  164.  
  165. double powrx;
  166. powrx=lossModel->CalcRxPower(16,mobil, mobil2);
  167. std::cout << powrx << " "<< std::endl; //out system loss
  168.  
  169. //Ptr<TwoRayGroundPropagationLossModel> propmode = wifiStaNodes.Get(0)->GetObject<TwoRayGroundPropagationLossModel> ();
  170. //double pos;
  171. //pos=propmode->GetSystemLoss();
  172. //std::cout << pos << " distance "<< std::endl;
  173.  
  174. //Ptr<YansWifiPhyHelper> propmode = wifiStaNodes.Get(0)->GetObject<YansWifiPhyHelper> ();
  175. //std::cout << propmode << " "<< std::endl;
  176. //Time m_dalay_m_m2= propmode->GetDelay(mobil, mobil2);
  177.  
  178. //TypeId propid = propmode->GetInstanceTypeId();
  179. //std1threshold::cout << propid.GetName() << " distance "<< std::endl;
  180.  
  181.  
  182.  
  183. Simulator::Stop (Seconds (30.0));
  184. /////////////////////////////PCAP tracing/////////////////////////////
  185. phy.EnablePcap ("LAB1", staDevices .Get (nWifi-1), true);
  186. phy.EnablePcap ("LAB1", staDevices .Get (0), true);
  187.  
  188.  
  189. Simulator::Run ();
  190. Simulator::Destroy ();
  191. return 0;
  192. };
RAW Paste Data