Guest User

Untitled

a guest
Oct 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. //in Agent.h
  2. class Agent : public ns3::Object{
  3. private:
  4. //...
  5.  
  6. static BaseWifi m_wifi;
  7.  
  8. //...
  9. };
  10.  
  11. //Agent.cpp
  12. BaseWifi temp;
  13. BaseWifi Agent::m_wifi = temp;
  14.  
  15. //Agent.cpp
  16. BaseWifi Agent::m_wifi = BaseWifi();
  17.  
  18. BaseWifi temp;
  19.  
  20. class BaseWifi {
  21. ns3::WifiHelper m_wifiHelper; // a wifi helper apply to setup vehicles Wifi
  22.  
  23. ns3::NqosWifiMacHelper m_wifiMacHelper; // a wifi mac helper apply to setup vehicles Wifi
  24.  
  25. ns3::YansWifiPhyHelper m_wifiPhyHelper; // a wifi phy helper apply to setup vehicles Wifi
  26.  
  27. std::string m_phyMode;
  28.  
  29. double m_rss; // -dBm
  30.  
  31. bool m_init_done;
  32.  
  33. public:
  34.  
  35. BaseWifi();
  36.  
  37. virtual void init();
  38.  
  39. ns3::NetDeviceContainer Install(ns3::NodeContainer &c);
  40.  
  41. virtual ~BaseWifi();
  42. };
  43.  
  44. BaseWifi::BaseWifi() {
  45. m_init_done = false;
  46. m_rss = -80;
  47. m_phyMode ="DsssRate1Mbps";
  48. // TODO Auto-generated constructor stub
  49. init();
  50. }
  51.  
  52. void BaseWifi::init() {
  53. NS_LOG_UNCOND("inside BaseWifi::init()");
  54. m_wifiHelper.SetStandard (ns3::WIFI_PHY_STANDARD_80211b);
  55.  
  56. m_wifiPhyHelper = ns3::YansWifiPhyHelper::Default ();
  57.  
  58. // This is one parameter that matters when using FixedRssLossModel
  59. // set it to zero; otherwise, gain will be added
  60. m_wifiPhyHelper.Set ("RxGain", ns3::DoubleValue (0) );
  61.  
  62. // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
  63. m_wifiPhyHelper.SetPcapDataLinkType (ns3::YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
  64.  
  65. ns3::YansWifiChannelHelper wifiChannel;
  66.  
  67. wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
  68.  
  69. // The below FixedRssLossModel will cause the rss to be fixed regardless
  70. // of the distance between the two stations, and the transmit power
  71. wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",ns3::DoubleValue (m_rss));
  72.  
  73. m_wifiPhyHelper.SetChannel (wifiChannel.Create ());
  74.  
  75. // Add a non-QoS upper mac, and disable rate control
  76. m_wifiMacHelper = ns3::NqosWifiMacHelper::Default ();
  77.  
  78. m_wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
  79. "DataMode",ns3::StringValue (m_phyMode),
  80. "ControlMode",ns3::StringValue (m_phyMode));
  81. // Set it to adhoc mode
  82. m_wifiMacHelper.SetType ("ns3::AdhocWifiMac");
  83.  
  84. m_init_done = true;
  85. }
  86.  
  87. //Install the class's embedded settings on the nodes in this node container.
  88. ns3::NetDeviceContainer BaseWifi::Install(ns3::NodeContainer &nc) {
  89. return m_wifiHelper.Install(m_wifiPhyHelper, m_wifiMacHelper, nc);
  90. }
  91.  
  92. //in Agent.h
  93. class Agent : public ns3::Object{
  94. private:
  95. //...
  96.  
  97. static BaseWifi& m_wifi();
  98. //...
  99. };
  100.  
  101. //in Agent.cpp
  102. BaseWifi& Agent::m_wifi() {
  103. static BaseWifi TheObject=BaseWifi();
  104. return TheObject;
  105. }
Add Comment
Please, Sign In to add comment