PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/kern/ap.cpp

https://gitlab.com/juan-/topologygenerator
C++ | 210 lines | 140 code | 39 blank | 31 comment | 6 complexity | 5068718c3c1098083a16cd48af443679 MD5 | raw file
  1. /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2. /*
  3. * Copyright (c) 2009 University of Strasbourg
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation;
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * Author: Pierre Weiss <3weissp@gmail.com>
  19. */
  20. /**
  21. * \file ap.cpp
  22. * \brief Ap link subclass.
  23. * \author Pierre Weiss
  24. * \date 2009
  25. */
  26. #include "ap.h"
  27. Ap::Ap(const std::string &type, const size_t &indice, const std::string &apNode) : NetworkHardware(type, indice)
  28. {
  29. this->Install(apNode);
  30. this->SetNetworkHardwareName(std::string("ap_" + this->GetIndice()));
  31. this->SetNdcName(std::string("ndc_" + this->GetNetworkHardwareName()));
  32. this->SetAllNodeContainer(std::string("all_" + this->GetNetworkHardwareName()));
  33. this->m_apNode = apNode;
  34. this->m_mobility = false;
  35. this->m_apName = std::string("wifi-default-" + this->GetIndice());
  36. }
  37. Ap::~Ap()
  38. {
  39. }
  40. std::string Ap::GetApNode()
  41. {
  42. return this->m_apNode;
  43. }
  44. void Ap::SetApNode(const std::string &apNode)
  45. {
  46. this->m_apNode = apNode;
  47. }
  48. void Ap::SetMobility(const bool &mobility)
  49. {
  50. this->m_mobility = mobility;
  51. }
  52. bool Ap::GetMobility()
  53. {
  54. return this->m_mobility;
  55. }
  56. void Ap::SetApName(const std::string &apName)
  57. {
  58. this->m_apName = apName;
  59. }
  60. std::string Ap::GetApName()
  61. {
  62. return this->m_apName;
  63. }
  64. std::vector<std::string> Ap::GenerateHeader()
  65. {
  66. std::vector<std::string> headers;
  67. headers.push_back("#include \"ns3/wifi-module.h\"");
  68. headers.push_back("#include \"ns3/mobility-module.h\"");
  69. headers.push_back("#include \"ns3/propagation-module.h\"");
  70. return headers;
  71. }
  72. std::vector<std::string> Ap::GenerateNetworkHardwareCpp()
  73. {
  74. std::vector<std::string> generatedLink;
  75. /* creation of the link. */
  76. generatedLink.push_back("YansWifiPhyHelper wifiPhy_" + this->GetNetworkHardwareName() + " = YansWifiPhyHelper::Default ();");
  77. generatedLink.push_back("YansWifiChannelHelper wifiChannel_" + this->GetNetworkHardwareName() + " = YansWifiChannelHelper::Default ();");
  78. generatedLink.push_back("wifiPhy_" + this->GetNetworkHardwareName() + ".SetChannel (wifiChannel_" + this->GetNetworkHardwareName() + ".Create ());");
  79. return generatedLink;
  80. }
  81. std::vector<std::string> Ap::GenerateNetDeviceCpp()
  82. {
  83. std::vector<std::string> ndc;
  84. std::vector<std::string> allNodes = this->GroupAsNodeContainerCpp(); //all station nodes !
  85. for(size_t i = 0; i < allNodes.size(); i++)
  86. {
  87. ndc.push_back(allNodes.at(i));
  88. }
  89. ndc.push_back("NetDeviceContainer " + this->GetNdcName() + ";");
  90. ndc.push_back("Ssid ssid_" + this->GetNetworkHardwareName() + " = Ssid (\"" + this->m_apName + "\");");
  91. ndc.push_back("WifiHelper wifi_" + this->GetNetworkHardwareName() + " = WifiHelper::Default ();");
  92. ndc.push_back("NqosWifiMacHelper wifiMac_" + this->GetNetworkHardwareName() + " = NqosWifiMacHelper::Default ();");
  93. ndc.push_back("wifi_" + this->GetNetworkHardwareName() + ".SetRemoteStationManager (\"ns3::ArfWifiManager\");");
  94. ndc.push_back("wifiMac_" + this->GetNetworkHardwareName() + ".SetType (\"ns3::StaWifiMac\", ");
  95. ndc.push_back(" \"Ssid\", SsidValue (ssid_" + this->GetNetworkHardwareName() + "), ");
  96. // ndc.push_back(" \"BeaconGeneration\", BooleanValue (true),");
  97. // ndc.push_back(" \"BeaconInterval\", TimeValue (Seconds (2.5)));");
  98. ndc.push_back(" \"ActiveProbing\", BooleanValue (false));");
  99. ndc.push_back(this->GetNdcName() + ".Add (wifi_" + this->GetNetworkHardwareName() + ".Install (wifiPhy_" + this->GetNetworkHardwareName() + ", wifiMac_" + this->GetNetworkHardwareName() + ", " + this->m_apNode + "));");
  100. ndc.push_back("wifiMac_" + this->GetNetworkHardwareName() + ".SetType (\"ns3::ApWifiMac\",");
  101. ndc.push_back(" \"Ssid\", SsidValue (ssid_" + this->GetNetworkHardwareName() + ")); ");
  102. ndc.push_back(this->GetNdcName() + ".Add (wifi_" + this->GetNetworkHardwareName() + ".Install (wifiPhy_" + this->GetNetworkHardwareName() + ", wifiMac_" + this->GetNetworkHardwareName() + ", " + this->GetAllNodeContainer() + " ));");
  103. ndc.push_back("MobilityHelper mobility_" + this->GetNetworkHardwareName() + ";");
  104. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".SetMobilityModel (\"ns3::ConstantPositionMobilityModel\");");
  105. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".Install (" + this->m_apNode + ");");
  106. if(this->m_mobility)//if random walk is activated.
  107. {
  108. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".SetMobilityModel (\"ns3::RandomWalk2dMobilityModel\",\"Bounds\", RectangleValue (Rectangle (-50, 50, -50, 50)));");
  109. }
  110. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".Install(" + this->GetAllNodeContainer() + ");");
  111. return ndc;
  112. }
  113. std::vector<std::string> Ap::GenerateTraceCpp()
  114. {
  115. std::vector<std::string> trace;
  116. if(this->GetTrace())
  117. {
  118. trace.push_back("wifiPhy_" + this->GetNetworkHardwareName() + ".EnablePcap (\"" + this->GetNetworkHardwareName() + "\", " + this->GetNdcName() + ".Get(0));");
  119. }
  120. return trace;
  121. }
  122. std::vector<std::string> Ap::GenerateNetworkHardwarePython()
  123. {
  124. std::vector<std::string> generatedLink;
  125. /* creation of the link. */
  126. generatedLink.push_back("wifiPhy_" + this->GetNetworkHardwareName() + " = ns3.YansWifiPhyHelper.Default()");
  127. generatedLink.push_back("wifiChannel_" + this->GetNetworkHardwareName() + " = ns3.YansWifiChannelHelper.Default()");
  128. generatedLink.push_back("wifiPhy_" + this->GetNetworkHardwareName() + ".SetChannel(wifiChannel_" + this->GetNetworkHardwareName() + ".Create())");
  129. return generatedLink;
  130. }
  131. std::vector<std::string> Ap::GenerateNetDevicePython()
  132. {
  133. std::vector<std::string> ndc;
  134. std::vector<std::string> allNodes = this->GroupAsNodeContainerPython(); //all station nodes !
  135. for(size_t i = 0; i < allNodes.size(); i++)
  136. {
  137. ndc.push_back(allNodes.at(i));
  138. }
  139. ndc.push_back(this->GetNdcName() + " = ns3.NetDeviceContainer()");
  140. ndc.push_back("ssid_" + this->GetNetworkHardwareName() + " = ns3.Ssid(\"" + this->m_apName + "\")");
  141. ndc.push_back("wifi_" + this->GetNetworkHardwareName() + " = ns3.WifiHelper.Default()");
  142. ndc.push_back("wifiMac_" + this->GetNetworkHardwareName() + " = ns3.NqosWifiMacHelper.Default()");
  143. ndc.push_back("wifi_" + this->GetNetworkHardwareName() + ".SetRemoteStationManager(\"ns3::ArfWifiManager\")");
  144. ndc.push_back("wifiMac_" + this->GetNetworkHardwareName() + ".SetType (\"ns3::StaWifiMac\", ");
  145. ndc.push_back(" \"Ssid\", ns3.SsidValue(ssid_" + this->GetNetworkHardwareName() + "), ");
  146. // ndc.push_back(" \"BeaconGeneration\", BooleanValue (true),");
  147. // ndc.push_back(" \"BeaconInterval\", TimeValue (Seconds (2.5)));");
  148. ndc.push_back(" \"ActiveProbing\", BooleanValue (false));");
  149. ndc.push_back(this->GetNdcName() + ".Add(wifi_" + this->GetNetworkHardwareName() + ".Install(wifiPhy_" + this->GetNetworkHardwareName() + ", wifiMac_" + this->GetNetworkHardwareName() + ", " + this->m_apNode + "))");
  150. ndc.push_back("wifiMac_" + this->GetNetworkHardwareName() + ".SetType(\"ns3::ApWifiMac\",");
  151. ndc.push_back(" \"Ssid\", ns3.SsidValue(ssid_" + this->GetNetworkHardwareName() + ")); ");
  152. ndc.push_back(this->GetNdcName() + ".Add(wifi_" + this->GetNetworkHardwareName() + ".Install(wifiPhy_" + this->GetNetworkHardwareName() + ", wifiMac_" + this->GetNetworkHardwareName() + ", " + this->GetAllNodeContainer() + " ))");
  153. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + " = ns3.MobilityHelper()");
  154. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".SetMobilityModel (\"ns3::ConstantPositionMobilityModel\")");
  155. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".Install(" + this->m_apNode + ")");
  156. if(this->m_mobility)//if random walk is activated.
  157. {
  158. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".SetMobilityModel (\"ns3::RandomWalk2dMobilityModel\",\"Bounds\", RectangleValue (Rectangle (-50, 50, -50, 50)))");
  159. }
  160. ndc.push_back("mobility_" + this->GetNetworkHardwareName() + ".Install(" + this->GetAllNodeContainer() + ")");
  161. return ndc;
  162. }
  163. std::vector<std::string> Ap::GenerateTracePython()
  164. {
  165. std::vector<std::string> trace;
  166. if(this->GetTrace())
  167. {
  168. trace.push_back("wifiPhy_" + this->GetNetworkHardwareName() + ".EnablePcap(\"" + this->GetNetworkHardwareName() + "\", " + this->GetNdcName() + ".Get(0))");
  169. }
  170. return trace;
  171. }