Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.77 KB | None | 0 0
  1. #include "ns3/core-module.h"
  2. #include "ns3/network-module.h"
  3. #include "ns3/mobility-module.h"
  4. #include "ns3/config-store.h"
  5. #include "ns3/mmwave-helper.h"
  6. #include <ns3/buildings-helper.h>
  7. #include "ns3/global-route-manager.h"
  8. #include "ns3/ipv4-global-routing-helper.h"
  9. #include "ns3/internet-module.h"
  10. #include "ns3/applications-module.h"
  11. #include "ns3/log.h"
  12. #include <iostream>
  13. #include "ns3/mmwave-helper.h"
  14. #include "ns3/core-module.h"
  15. #include "ns3/network-module.h"
  16. #include "ns3/mobility-module.h"
  17. #include "ns3/config-store.h"
  18. #include "ns3/mmwave-helper.h"
  19. #include "ns3/log.h"
  20. #include "ns3/nr-point-to-point-epc-helper.h"
  21. #include "ns3/network-module.h"
  22. #include "ns3/ipv4-global-routing-helper.h"
  23. #include "ns3/internet-module.h"
  24. #include "ns3/applications-module.h"
  25. #include "ns3/point-to-point-helper.h"
  26. #include "ns3/eps-bearer-tag.h"
  27. #include "ns3/abort.h"
  28. #include "ns3/object.h"
  29. #include "ns3/mmwave-mac-scheduler-ns3.h"
  30. #include "ns3/mmwave-mac-scheduler-ofdma.h"
  31. #include "ns3/mmwave-mac-scheduler-ofdma-rr.h"
  32. #include "ns3/mmwave-phy-mac-common.h"
  33. #include "ns3/basic-data-calculators.h"
  34. #include "ns3/antenna-array-3gpp-model.h"
  35. #include "ns3/netanim-module.h"
  36. #include <iostream>
  37. #include <cmath>
  38. #include <ctime>
  39. #include "ns3/mmwave-enb-mac.h"
  40. #include "ns3/mmwave-enb-mac.h"
  41. #include "ns3/mmwave-phy-mac-common.h"
  42. #include "ns3/mmwave-mac-pdu-header.h"
  43. #include "ns3/mmwave-mac-sched-sap.h"
  44. #include "ns3/mmwave-mac-scheduler.h"
  45. #include "ns3/mmwave-control-messages.h"
  46. #include <ns3/lte-radio-bearer-tag.h>
  47. #include <ns3/log.h>
  48. #include <thread>
  49.  
  50. #include "ns3/gnuplot.h"
  51. #include "ns3/command-line.h"
  52. #include "ns3/config.h"
  53. #include "ns3/uinteger.h"
  54. #include "ns3/double.h"
  55. #include "ns3/log.h"
  56. #include "ns3/yans-wifi-helper.h"
  57. #include "ns3/ssid.h"
  58. #include "ns3/mobility-helper.h"
  59. #include "ns3/internet-stack-helper.h"
  60. #include "ns3/ipv4-address-helper.h"
  61. #include "ns3/packet-sink-helper.h"
  62. #include "ns3/on-off-helper.h"
  63. #include "ns3/yans-wifi-channel.h"
  64. #include "ns3/wifi-net-device.h"
  65. #include "ns3/wifi-mac.h"
  66. #include "ns3/wifi-mac-header.h"
  67. #include "ns3/mobility-model.h"
  68. #include "ns3/propagation-loss-model.h"
  69. #include "ns3/flow-monitor.h"
  70. #include "ns3/flow-monitor-helper.h"
  71. #include "ns3/ipv4-flow-classifier.h"
  72. #include "ns3/ipv4-global-routing-helper.h"
  73.  
  74. using namespace ns3;
  75. using namespace std;
  76.  
  77. int j =0;
  78.  
  79. double rssi1=0.0;
  80. double rssi2=0.0;
  81. double rssi3=0.0;
  82.  
  83. int count1, count2, count3;
  84.  
  85. double maxPower = 23;
  86. double minPower = 0;
  87.  
  88. double frequency = 30e9;
  89. double C = 299792458.0;
  90. double m_lambda = C / frequency;
  91. double m_systemLoss = 1.0;
  92. double m_minLoss = 0;
  93. double m_pi = 3.141592;
  94.  
  95. struct point
  96. {
  97. double x,y;
  98. };
  99.  
  100. double norm (point p) // get the norm of a vector
  101. {
  102. return pow(pow(p.x,2)+pow(p.y,2),.5);
  103. }
  104.  
  105.  
  106.  
  107.  
  108. //#########################################################
  109. //#########################################################
  110.  
  111. point trilateration(point point1, point point2, point point3, double r1, double r2, double r3) {
  112. point resultPose;
  113. //unit vector in a direction from point1 to point 2
  114. double p2p1Distance = pow(pow(point2.x-point1.x,2) + pow(point2.y- point1.y,2),0.5);
  115. point ex = {(point2.x-point1.x)/p2p1Distance, (point2.y-point1.y)/p2p1Distance};
  116. point aux = {point3.x-point1.x,point3.y-point1.y};
  117. //signed magnitude of the x component
  118. double i = ex.x * aux.x + ex.y * aux.y;
  119. //the unit vector in the y direction.
  120. point aux2 = { point3.x-point1.x-i*ex.x, point3.y-point1.y-i*ex.y};
  121. point ey = { aux2.x / norm (aux2), aux2.y / norm (aux2) };
  122. //the signed magnitude of the y component
  123. double j = ey.x * aux.x + ey.y * aux.y;
  124. //coordinates
  125. double x = (pow(r1,2) - pow(r2,2) + pow(p2p1Distance,2))/ (2 * p2p1Distance);
  126. double y = (pow(r1,2) - pow(r3,2) + pow(i,2) + pow(j,2))/(2*j) - i*x/j;
  127. //result coordinates
  128. double finalX = point1.x+ x*ex.x + y*ey.x;
  129. double finalY = point1.y+ x*ex.y + y*ey.y;
  130. resultPose.x = finalX;
  131. resultPose.y = finalY;
  132. return resultPose;
  133. }
  134.  
  135.  
  136. double doCalcDistance(double Pt, double Pr)
  137. {
  138. /*
  139. double loss = Pt - Pr;
  140. double x = pow(10, (loss / -10));
  141. double xx = (m_lambda * m_lambda) / x;
  142. double xxx = xx / m_systemLoss / 16 / m_pi / m_pi;
  143. double distance = sqrt(xxx);
  144. return distance;
  145. */
  146.  
  147. return pow(10, (Pr-(-31.3))/(-10 * 2));
  148.  
  149. }
  150.  
  151.  
  152.  
  153. //#########################################################
  154. //#########################################################
  155.  
  156.  
  157. enum AntennaModelEnum{
  158. _ISO,
  159. _3GPP,
  160. };
  161.  
  162.  
  163.  
  164. static ns3::GlobalValue g_duration ("duration",
  165. "simulation duration in milliseconds, should be greater than 100 ms to allow the collection of traces",
  166. ns3::UintegerValue (150),
  167. ns3::MakeUintegerChecker<uint32_t>());
  168.  
  169. static ns3::GlobalValue g_shadowing ("shadowing",
  170. "if true, shadowing is enabled in 3gpp propagation loss model;"
  171. "if false, shadowing is disabled",
  172. ns3::BooleanValue (true),
  173. ns3::MakeBooleanChecker ());
  174.  
  175. static ns3::GlobalValue g_antennaOrientation ("antennaOrientation",
  176. "the orientation of the antenna on gNB and UE",
  177. ns3::EnumValue (AntennaArray3gppModel::Z0),
  178. ns3::MakeEnumChecker (AntennaArray3gppModel::Z0, "Z0",
  179. AntennaArray3gppModel::X0, "X0"));
  180. static ns3::GlobalValue g_antennaModelgNb ("antennaModelGnb",
  181. "the antenna model of gNb, can be ISO or 3GPP",
  182. ns3::EnumValue (_3GPP),
  183. ns3::MakeEnumChecker (_ISO, "ISO",
  184. _3GPP, "3GPP"));
  185.  
  186. static ns3::GlobalValue g_antennaModelUe ("antennaModelUe",
  187. "the antenna model of Ue, can be ISO or 3GPP",
  188. ns3::EnumValue (_3GPP),
  189. ns3::MakeEnumChecker (_ISO, "ISO",
  190. _3GPP, "3GPP"));
  191.  
  192. static ns3::GlobalValue g_resultsDir ("resultsDir",
  193. "directory where to store the simulation results",
  194. ns3::StringValue ("./"),
  195. ns3::MakeStringChecker ());
  196.  
  197. static ns3::GlobalValue g_simTag ("simTag",
  198. "tag to be appended to the output filenames to distinguish different simulation campaign output files",
  199. ns3::StringValue (""),
  200. ns3::MakeStringChecker ());
  201.  
  202. static ns3::GlobalValue g_indoorScenario ("indoorScenario",
  203. "the indoor scenario to be used can be: InH-OfficeMixed, InH-OfficeOpen or InH-ShoppingMall",
  204. ns3::StringValue ("InH-OfficeOpen"),
  205. ns3::MakeStringChecker ());
  206.  
  207. static ns3::GlobalValue g_speed ("speed",
  208. "UE speed in km/h",
  209. ns3::DoubleValue (3.00),
  210. ns3::MakeDoubleChecker<double> (0.0, 10.0));
  211.  
  212. static ns3::GlobalValue g_isBeamSearchMethod ("isBeamSearchMethod",
  213. "if true, beam search method will be used;"
  214. "if false, long term covariance matrix will be used",
  215. ns3::BooleanValue (true),
  216. ns3::MakeBooleanChecker ());
  217.  
  218. static ns3::GlobalValue g_beamSearchMethodAngle ("beamSearchMethodAngle",
  219. "beam search method angle step",
  220. ns3::DoubleValue (5.0),
  221. ns3::MakeDoubleChecker<double> (0.0, 360.0));
  222.  
  223. static ns3::GlobalValue g_gNbAntennaMount ("gnbAntennaMount",
  224. "gNb antenna mount type. Can be Wall mount or Sector mount. Doc: 38.802-e20. A.2.1-7",
  225. ns3::EnumValue (ns3::AntennaArray3gppModel::GnbWallMount),
  226. ns3::MakeEnumChecker (ns3::AntennaArray3gppModel::GnbWallMount, "WALL",
  227. ns3::AntennaArray3gppModel::GnbSingleSector, "SECT"));
  228.  
  229.  
  230. //############################
  231.  
  232. void LocationUE (NodeContainer ue, NodeContainer gnb)
  233. {
  234. cout<<"At: "<<Simulator::Now().GetSeconds()<<" Seconds"<<endl;
  235.  
  236.  
  237. ofstream m_distace;
  238. m_distace.open("distance"+to_string(j)+".txt");
  239.  
  240. for(int i = 0; i<12;i++)
  241. {
  242. Vector posGNB=gnb.Get (i)->GetObject<ConstantPositionMobilityModel> ()->GetPosition();
  243. Vector posUE=ue.Get (i)->GetObject<ConstantPositionMobilityModel> ()->GetPosition();
  244. cout<<"At: "<<Simulator::Now().GetSeconds()<<" "<<" Node #"<<i+1<<"\t"<<"(" <<posUE.x <<","<<posUE.y<<")"<<endl;
  245.  
  246. double dis;
  247. string str= " ";
  248. dis = sqrt( pow((posUE.x - posGNB.x), 2.0) + pow((posUE.y - posGNB.y),2.0) + pow((posUE.z - posGNB.z), 2.0));
  249. m_distace<<i<<str<<dis<<std::endl;
  250.  
  251.  
  252. }
  253. cout<<"######################################"<<endl;
  254.  
  255. j++;
  256.  
  257. }
  258.  
  259.  
  260.  
  261. void SetInitialVelocity(NodeContainer ue)
  262. {
  263. ue.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (300, 0, 0));
  264.  
  265.  
  266. }
  267.  
  268. void CourseChange(NodeContainer ue, int c)
  269. {
  270. if(c==1) //Move into the Y Access
  271. {
  272. cout<<"Change course into +Y Access"<<endl;
  273. ue.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.831, 0));
  274. ue.Get (1)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8334, 0));
  275. ue.Get (2)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8335, 0));
  276. ue.Get (3)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8333, 0));
  277. ue.Get (4)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8323, 0));
  278. ue.Get (5)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.833, 0));
  279. ue.Get (6)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.83734, 0));
  280. ue.Get (7)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.83344, 0));
  281. ue.Get (8)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.83743, 0));
  282. ue.Get (9)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.83434, 0));
  283. ue.Get (10)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8341, 0));
  284. ue.Get (11)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, 50.8324, 0));
  285.  
  286.  
  287. }
  288. if(c==2) //Move back into the X Access in minus
  289. {
  290. cout<<"Change course into -X Access"<<endl;
  291. ue.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.831, 0, 0));
  292. ue.Get (1)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8334, 0, 0));
  293. ue.Get (2)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8335, 0, 0));
  294. ue.Get (3)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8333, 0, 0));
  295. ue.Get (4)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8323, 0, 0));
  296. ue.Get (5)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.833, 0, 0));
  297. ue.Get (6)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.83734, 0, 0));
  298. ue.Get (7)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.83344, 0, 0));
  299. ue.Get (8)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.83743, 0, 0));
  300. ue.Get (9)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.83434, 0, 0));
  301. ue.Get (10)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8341, 0, 0));
  302. ue.Get (11)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (-50.8324, 0, 0));
  303.  
  304. }
  305.  
  306. if(c==3) //Move back into the Y Access in minus
  307. {
  308. cout<<"Change course into -Y Access"<<endl;
  309. ue.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.831, 0));
  310. ue.Get (1)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8334, 0));
  311. ue.Get (2)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8335, 0));
  312. ue.Get (3)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8333, 0));
  313. ue.Get (4)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8323, 0));
  314. ue.Get (5)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.833, 0));
  315. ue.Get (6)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.83734, 0));
  316. ue.Get (7)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.83344, 0));
  317. ue.Get (8)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.83743, 0));
  318. ue.Get (9)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.83434, 0));
  319. ue.Get (10)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8341, 0));
  320. ue.Get (11)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (0, -50.8324, 0));
  321.  
  322. }
  323.  
  324. if(c==4) //Move back into the +X Access
  325. {
  326. ue.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.831, 0, 0));
  327. ue.Get (1)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8334, 0, 0));
  328. ue.Get (2)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8335, 0, 0));
  329. ue.Get (3)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8333, 0, 0));
  330. ue.Get (4)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8323, 0, 0));
  331. ue.Get (5)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.833, 0, 0));
  332. ue.Get (6)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.83734, 0, 0));
  333. ue.Get (7)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.83344, 0, 0));
  334. ue.Get (8)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.83743, 0, 0));
  335. ue.Get (9)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.83434, 0, 0));
  336. ue.Get (10)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8341, 0, 0));
  337. ue.Get (11)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (50.8324, 0, 0));
  338.  
  339. }
  340.  
  341. }
  342.  
  343. class nr{
  344.  
  345. public:
  346.  
  347. void UeRssiPerProcessedChunk1 (double rssidBm);
  348. void UeRssiPerProcessedChunk2 (double rssidBm);
  349. void UeRssiPerProcessedChunk3 (double rssidBm);
  350.  
  351. void Run (bool shadowing, AntennaArrayModel::AntennaOrientation antOrientation, TypeId gNbAntennaModel,
  352. TypeId ueAntennaModel, std::string scenario, double speed,
  353. std::string resultsDirPath, std::string tag,
  354. bool isBeamSearchMethod, double beamSearchMethodAngle,
  355. AntennaArray3gppModel::GnbAntennaMount gNbAntennaMount, uint32_t duration);
  356. ~nr ();
  357.  
  358. private:
  359. ofstream m_outRssiFile1;
  360.  
  361.  
  362.  
  363. };
  364.  
  365.  
  366. //#####################################################
  367. //#####################################################
  368. //#####################################################
  369.  
  370.  
  371. void nr::UeRssiPerProcessedChunk1 (double rssidBm)
  372. {
  373. count1++;
  374. string str= " ";
  375. m_outRssiFile1<<Simulator::Now().GetSeconds()<<str<<rssidBm<<std::endl;
  376. //cout<<Simulator::Now().GetSeconds()<<str<< rssidBm<<endl;
  377. rssi1= rssi1+rssidBm;
  378.  
  379. }
  380.  
  381.  
  382. void UeRssiPerProcessedChunkTrace1 (nr* scenario, double rssidBm)
  383. {
  384. scenario->UeRssiPerProcessedChunk1 (rssidBm);
  385. }
  386.  
  387.  
  388. //#####################################################
  389. //#####################################################
  390.  
  391.  
  392.  
  393. void nr::Run(bool shadowing, AntennaArrayModel::AntennaOrientation antOrientation,
  394. TypeId gNbAntennaModel, TypeId ueAntennaModel, std::string scenario, double speed,
  395. std::string resultsDirPath, std::string tag,
  396. bool isBeamSearchMethod, double beamSearchMethodAngle,
  397. AntennaArray3gppModel::GnbAntennaMount gNbAntennaMount, uint32_t duration)
  398. {
  399. m_outRssiFile1.open ("RssiValues1.txt");
  400.  
  401.  
  402.  
  403. Config::SetDefault ("ns3::AntennaArray3gppModel::GnbAntennaMountType", EnumValue (gNbAntennaMount));
  404. Config::SetDefault ("ns3::AntennaArrayModel::AntennaOrientation", EnumValue (antOrientation));
  405. // configure antenna gain for the ISO antenna
  406. Config::SetDefault ("ns3::AntennaArrayModel::AntennaGain", DoubleValue (5));
  407. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Scenario", StringValue(scenario));
  408. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Shadowing", BooleanValue(shadowing));
  409. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Frequency", DoubleValue(30e9));
  410. // Config::SetDefault ("ns3::MmWave3gppChannel::UpdatePeriod", TimeValue(MilliSeconds(100))); // interval after which the channel for a moving user is updated,
  411.  
  412. // with spatial consistency procedure. If 0, spatial consistency is not used
  413.  
  414. // we tried also with the optional nLos model and both 3gpp antennas, and it is not better calibrated
  415. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::OptionalNlos", BooleanValue(false));
  416.  
  417. // Default scenario configuration that are summarised in to R1-1703534 3GPP TSG RAN WG1 Meeting #88
  418. Config::SetDefault ("ns3::MmWave3gppChannel::Speed", DoubleValue (speed*1000/3600));
  419. // Disable channel matrix update to speed up the simulation execution
  420. Config::SetDefault ("ns3::MmWave3gppChannel::UpdatePeriod", TimeValue (MilliSeconds(0)));
  421. Config::SetDefault ("ns3::MmWavePhyMacCommon::MacSchedulerType", TypeIdValue (TypeId::LookupByName("ns3::MmWaveMacSchedulerTdmaPF")));
  422.  
  423. Config::SetDefault ("ns3::MmWave3gppChannel::CellScan", BooleanValue (isBeamSearchMethod));
  424. Config::SetDefault ("ns3::MmWave3gppChannel::BeamSearchAngleStep", DoubleValue (beamSearchMethodAngle));
  425.  
  426. Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue (320));
  427. // Parameters according to R1-1703534 3GPP TSG RAN WG1 Meetging #88, 2017
  428. // Evaluation assumptions for Phase 1 NR MIMO system level calibration,
  429. Config::SetDefault ("ns3::MmWaveEnbPhy::TxPower", DoubleValue(23));
  430. Config::SetDefault ("ns3::MmWavePhyMacCommon::CenterFreq", DoubleValue(30e9));
  431. Config::SetDefault ("ns3::MmWavePhyMacCommon::Numerology", UintegerValue(2));
  432. Config::SetDefault ("ns3::MmWavePhyMacCommon::Bandwidth", DoubleValue(40e6));
  433.  
  434. // Should be 4x8 = 32 antenna elements
  435. Config::SetDefault ("ns3::MmWaveEnbPhy::AntennaArrayType", TypeIdValue(gNbAntennaModel));
  436. Config::SetDefault ("ns3::MmWaveEnbPhy::AntennaNumDim1", UintegerValue(8));
  437. Config::SetDefault ("ns3::MmWaveEnbPhy::AntennaNumDim2", UintegerValue(8));
  438.  
  439. // Should be 2x4 = 8 antenna elements
  440. Config::SetDefault ("ns3::MmWaveUePhy::AntennaArrayType", TypeIdValue(ueAntennaModel));
  441. Config::SetDefault ("ns3::MmWaveUePhy::AntennaNumDim1", UintegerValue(4));
  442. Config::SetDefault ("ns3::MmWaveUePhy::AntennaNumDim2", UintegerValue(4));
  443.  
  444. // UE antenna gain shall be set to 5 dBi
  445. // gNB noise figure shall be set to 7 dB
  446. Config::SetDefault("ns3::MmWaveEnbPhy::NoiseFigure", DoubleValue (7));
  447. // UE noise figure shall be set to 10 dB
  448. Config::SetDefault("ns3::MmWaveUePhy::NoiseFigure", DoubleValue (10));
  449. // set LOS,NLOS condition
  450. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::ChannelCondition", StringValue("a"));
  451. // setup the mmWave simulation
  452.  
  453.  
  454. Ptr<MmWaveHelper> ptr_mmv = CreateObject<MmWaveHelper>();
  455.  
  456. ptr_mmv->SetAttribute("ChannelModel", StringValue("ns3::MmWave3gppChannel"));
  457. ptr_mmv->SetAttribute("PathlossModel", StringValue("ns3::MmWave3gppPropagationLossModel"));
  458.  
  459.  
  460. Ptr<NrPointToPointEpcHelper> epcHelper = CreateObject<NrPointToPointEpcHelper> ();
  461. ptr_mmv->SetEpcHelper (epcHelper);
  462. ptr_mmv->Initialize();
  463.  
  464.  
  465. NodeContainer enb;
  466. NodeContainer ue;
  467. enb.Create(1);
  468. ue.Create(1);
  469.  
  470.  
  471. Ptr<ListPositionAllocator> enbposaloc = CreateObject<ListPositionAllocator>();
  472. enbposaloc->Add(Vector( 10, 15, 3));
  473.  
  474.  
  475. MobilityHelper enbmob;
  476. enbmob.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  477. enbmob.SetPositionAllocator(enbposaloc);
  478. enbmob.Install(enb);
  479.  
  480. MobilityHelper uemob;
  481.  
  482. uemob.SetMobilityModel("ns3::ConstantVelocityMobilityModel");
  483.  
  484.  
  485.  
  486. uemob.Install(ue);
  487.  
  488.  
  489. ue.Get (0)->GetObject<MobilityModel> ()->SetPosition (Vector (11, 15, 1.5));
  490.  
  491.  
  492. SetInitialVelocity(ue);
  493.  
  494.  
  495.  
  496. NetDeviceContainer enbnetdev = ptr_mmv->InstallEnbDevice (enb);
  497. NetDeviceContainer uenetdev = ptr_mmv->InstallUeDevice (ue);
  498.  
  499.  
  500. //#######################################
  501.  
  502. // create the internet and install the IP stack on the UEs
  503. // get SGW/PGW and create a single RemoteHost
  504. Ptr<Node> pgw = epcHelper->GetPgwNode ();
  505. NodeContainer remoteHostContainer;
  506. remoteHostContainer.Create (1);
  507. Ptr<Node> remoteHost = remoteHostContainer.Get (0);
  508. InternetStackHelper internet;
  509. internet.Install (remoteHostContainer);
  510.  
  511. // connect a remoteHost to pgw. Setup routing too
  512. PointToPointHelper p2ph;
  513.  
  514. p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
  515. p2ph.SetDeviceAttribute ("Mtu", UintegerValue (2500));
  516. p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.000)));
  517. NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
  518. Ipv4AddressHelper ipv4h;
  519. ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
  520. Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
  521. // in this container, interface 0 is the pgw, 1 is the remoteHost
  522. //Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
  523.  
  524. Ipv4StaticRoutingHelper ipv4RoutingHelper;
  525. Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
  526. remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
  527. internet.Install (ue);
  528. Ipv4InterfaceContainer ueIpIface;
  529. ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (uenetdev));
  530.  
  531.  
  532. for (uint32_t k = 0; k < 1; ++k)
  533. {
  534. Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue.Get(k)->GetObject<Ipv4> ());
  535. ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
  536. }
  537.  
  538.  
  539. ptr_mmv->AttachToEnb (uenetdev.Get(0),enbnetdev.Get(0));
  540.  
  541.  
  542. uint16_t dlPort = 1234;
  543. ApplicationContainer clientAppsDl;
  544. ApplicationContainer serverAppsDl;
  545. DataRate udpRate = DataRate ("4Mbps");
  546. Time udpInterval = Time::FromDouble((1000*8) / static_cast<double> (udpRate.GetBitRate ()), Time::S);
  547.  
  548. UdpServerHelper dlPacketSinkHelper (dlPort);
  549. serverAppsDl.Add (dlPacketSinkHelper.Install (ue));
  550. // configure UDP downlink traffic
  551.  
  552. UdpClientHelper dlClient (ueIpIface.GetAddress (0), dlPort); //CHECK AFTER
  553. dlClient.SetAttribute ("MaxPackets", UintegerValue(0xFFFFFFFF));
  554. dlClient.SetAttribute("PacketSize", UintegerValue(1000));
  555. dlClient.SetAttribute ("Interval", TimeValue (udpInterval)); // we try to saturate, we just need to measure during a short time, how much traffic can handle each BWP
  556. clientAppsDl.Add (dlClient.Install (remoteHost));
  557.  
  558. Time udpAppStartTimeDl = MilliSeconds (100);
  559. Time udpAppStopTimeDl = MilliSeconds (300);
  560.  
  561. // start UDP server and client apps
  562. serverAppsDl.Start(udpAppStartTimeDl);
  563. clientAppsDl.Start(udpAppStartTimeDl);
  564.  
  565. serverAppsDl.Stop(udpAppStopTimeDl);
  566. clientAppsDl.Stop(udpAppStopTimeDl);
  567.  
  568. //LocationUE(ue,enb);
  569.  
  570. //#######################################
  571.  
  572.  
  573. Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy1 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(0))->GetPhy(0)->GetSpectrumPhy();
  574. Ptr<mmWaveInterference> ue1SpectrumPhyInterference1 = ue1SpectrumPhy1->GetMmWaveInterference();
  575. NS_ABORT_IF(!ue1SpectrumPhyInterference1);
  576. ue1SpectrumPhyInterference1->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace1, this));
  577.  
  578. LogComponentEnable ("MmWave3gppPropagationLossModel", LOG_LEVEL_ALL);
  579. //LogComponentEnable ("mmWaveInterference", LOG_LEVEL_ALL);
  580.  
  581. //p2ph.EnablePcapAll("x");
  582.  
  583. /*
  584. Simulator:: Schedule (Seconds(0.1), &LocationUE, ue, enb);
  585. Simulator:: Schedule (Seconds(0.2), &LocationUE, ue, enb);
  586. Simulator:: Schedule (Seconds(0.3), &LocationUE, ue, enb);
  587. Simulator:: Schedule (Seconds(0.8), &LocationUE, ue, enb);
  588. Simulator:: Schedule (Seconds(0.9), &LocationUE, ue, enb);
  589. Simulator:: Schedule (Seconds(1), &LocationUE, ue, enb);
  590. Simulator:: Schedule (Seconds(1.1), &LocationUE, ue, enb);
  591. Simulator:: Schedule (Seconds(1.2), &LocationUE, ue, enb);
  592. Simulator:: Schedule (Seconds(1.3), &LocationUE, ue, enb);
  593. Simulator:: Schedule (Seconds(1.9), &LocationUE, ue, enb);
  594. Simulator:: Schedule (Seconds(2), &LocationUE, ue, enb);
  595.  
  596.  
  597. Simulator:: Schedule (Seconds(2), &CourseChange, ue, 1);
  598.  
  599. Simulator:: Schedule (Seconds(2.2), &LocationUE, ue, enb);
  600. Simulator:: Schedule (Seconds(2.3), &LocationUE, ue, enb);
  601.  
  602. Simulator:: Schedule (Seconds(2.5), &CourseChange, ue, 2);
  603.  
  604. Simulator:: Schedule (Seconds(2.6), &LocationUE, ue, enb);
  605. Simulator:: Schedule (Seconds(2.9), &LocationUE, ue, enb);
  606.  
  607. Simulator:: Schedule (Seconds(3.3), &CourseChange, ue, 3);
  608.  
  609. Simulator:: Schedule (Seconds(3.5), &LocationUE, ue, enb);
  610.  
  611. Simulator:: Schedule (Seconds(3.8), &CourseChange, ue, 4);
  612. Simulator:: Schedule (Seconds(3.8), &LocationUE, ue, enb);
  613.  
  614. Simulator:: Schedule (Seconds(4), &LocationUE, ue, enb);
  615. */
  616.  
  617. Simulator::Stop (MilliSeconds (180));
  618. Simulator::Run ();
  619. /*
  620. double x1,x2,x3;
  621. point ue1;
  622. point xy1,xy2,xy3;
  623. xy1 = {10,15};
  624. xy2 = {10,35};
  625. xy3 = {30,15};
  626. cout<<"\nThe RSSI Averages: \n"<<rssi1/count1<<"\n"<<rssi2/count2<<"\n"<<rssi3/count3<<endl<<endl;
  627.  
  628.  
  629.  
  630. x1=doCalcDistance(23.0,rssi1/count1);
  631. x2=doCalcDistance(23.0,rssi2/count2);
  632. x3=doCalcDistance(23.0,rssi3/count3);
  633. cout<<x1<<" "<<x2<<" "<<x3 <<endl;
  634. ue1= trilateration(xy1,xy2,xy3,x1,x2,x3);
  635. cout<<"\n"<<ue1.x<<","<<ue1.y<<endl;
  636.  
  637. LocationUE(ue,enb);
  638.  
  639. cout<<endl;
  640. */
  641. Simulator::Destroy ();
  642.  
  643. }
  644.  
  645.  
  646. nr::~nr ()
  647. {
  648.  
  649. cout<<"Exiting"<<endl;
  650. m_outRssiFile1.close();
  651.  
  652.  
  653. }
  654.  
  655.  
  656. int main(int argc, char *argv[])
  657. {
  658.  
  659. CommandLine cmd;
  660. cmd.Parse (argc, argv);
  661. ConfigStore inputConfig;
  662. inputConfig.ConfigureDefaults ();
  663. // parse again so you can override input file default values via command line
  664. cmd.Parse (argc, argv);
  665. EnumValue enumValue;
  666. DoubleValue doubleValue;
  667. BooleanValue booleanValue;
  668. StringValue stringValue;
  669. TypeIdValue typeIdValue;
  670. UintegerValue uintValue;
  671.  
  672. GlobalValue::GetValueByName ("duration", uintValue);
  673. uint32_t duration = uintValue.Get ();
  674.  
  675. GlobalValue::GetValueByName ("shadowing", booleanValue);
  676. bool shadowing = booleanValue.Get ();
  677.  
  678. GlobalValue::GetValueByName ("antennaOrientation", enumValue);
  679. enum AntennaArray3gppModel::AntennaOrientation antennaOrientation = (AntennaArray3gppModel::AntennaOrientation) enumValue.Get ();
  680.  
  681. GlobalValue::GetValueByName ("antennaModelGnb", enumValue);
  682. enum AntennaModelEnum antennaGnb = (AntennaModelEnum) enumValue.Get ();
  683. TypeId antennaModelGnb;
  684. if (antennaGnb == _3GPP)
  685. {
  686. antennaModelGnb = AntennaArray3gppModel::GetTypeId();
  687. }
  688. else
  689. {
  690. antennaModelGnb = AntennaArrayModel::GetTypeId();
  691. }
  692.  
  693. GlobalValue::GetValueByName ("antennaModelUe", enumValue);
  694. enum AntennaModelEnum antennaUe = (AntennaModelEnum) enumValue.Get ();
  695. TypeId antennaModelUe;
  696. if (antennaUe == _3GPP)
  697. {
  698. antennaModelUe = AntennaArray3gppModel::GetTypeId();
  699. }
  700. else
  701. {
  702. antennaModelUe = AntennaArrayModel::GetTypeId();
  703. }
  704.  
  705. GlobalValue::GetValueByName ("indoorScenario", stringValue);
  706. std::string indoorScenario = stringValue.Get ();
  707.  
  708. GlobalValue::GetValueByName ("speed", doubleValue);
  709. double speed = doubleValue.Get ();
  710.  
  711. GlobalValue::GetValueByName ("resultsDir", stringValue);
  712. std::string resultsDir = stringValue.Get ();
  713.  
  714. GlobalValue::GetValueByName ("simTag", stringValue);
  715. std::string tag = stringValue.Get ();
  716.  
  717. GlobalValue::GetValueByName ("isBeamSearchMethod", booleanValue);
  718. bool isBeamSearchMethod = booleanValue.Get ();
  719.  
  720. GlobalValue::GetValueByName ("beamSearchMethodAngle", doubleValue);
  721. double beamSearchMethodAngle = doubleValue.Get ();
  722.  
  723. GlobalValue::GetValueByName ("gnbAntennaMount", enumValue);
  724. enum AntennaArray3gppModel::GnbAntennaMount gnbAntennaMount = (AntennaArray3gppModel::GnbAntennaMount) enumValue.Get ();
  725.  
  726.  
  727. nr phase1CalibrationScenario;
  728. phase1CalibrationScenario.Run(shadowing, antennaOrientation, antennaModelGnb, antennaModelUe,
  729. indoorScenario, speed, resultsDir, tag, isBeamSearchMethod, beamSearchMethodAngle, gnbAntennaMount, duration);
  730.  
  731.  
  732. return 0;
  733. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement