Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 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.  
  49.  
  50.  
  51. using namespace ns3;
  52. using namespace std;
  53.  
  54.  
  55. class nr{
  56.  
  57. public:
  58.  
  59. void UeRssiPerProcessedChunk1 (double rssidBm);
  60. void UeRssiPerProcessedChunk2 (double rssidBm);
  61. void UeRssiPerProcessedChunk3 (double rssidBm);
  62. void Run();
  63. ~nr ();
  64.  
  65. private:
  66. ofstream m_outRssiFile1;
  67. ofstream m_outRssiFile2;
  68. ofstream m_outRssiFile3;
  69. };
  70.  
  71. void nr::UeRssiPerProcessedChunk1 (double rssidBm)
  72. {
  73. string str= " ";
  74. m_outRssiFile1<<Simulator::Now().GetSeconds()<<str<<rssidBm<<std::endl;
  75. cout<<Simulator::Now().GetSeconds()<<str<< rssidBm<<endl;
  76.  
  77. }
  78.  
  79.  
  80. void UeRssiPerProcessedChunkTrace1 (nr* scenario, double rssidBm)
  81. {
  82. scenario->UeRssiPerProcessedChunk1 (rssidBm);
  83. }
  84.  
  85.  
  86. void nr::UeRssiPerProcessedChunk2 (double rssidBm)
  87. {
  88. string str= " ";
  89. m_outRssiFile2<<Simulator::Now().GetSeconds()<<str<<rssidBm<<std::endl;
  90. cout<<Simulator::Now().GetSeconds()<<str<< rssidBm<<endl;
  91.  
  92. }
  93.  
  94.  
  95. void UeRssiPerProcessedChunkTrace2 (nr* scenario, double rssidBm)
  96. {
  97. scenario->UeRssiPerProcessedChunk2 (rssidBm);
  98. }
  99.  
  100.  
  101. void nr::UeRssiPerProcessedChunk3 (double rssidBm)
  102. {
  103. string str= " ";
  104. m_outRssiFile3<<Simulator::Now().GetSeconds()<<str<<rssidBm<<std::endl;
  105. cout<<Simulator::Now().GetSeconds()<<str<< rssidBm<<endl;
  106.  
  107. }
  108.  
  109.  
  110. void UeRssiPerProcessedChunkTrace3 (nr* scenario, double rssidBm)
  111. {
  112. scenario->UeRssiPerProcessedChunk3 (rssidBm);
  113. }
  114.  
  115.  
  116.  
  117. void nr::Run()
  118. {
  119. m_outRssiFile1.open ("RssiValues1.txt");
  120. m_outRssiFile2.open ("RssiValues2.txt");
  121. m_outRssiFile3.open ("RssiValues3.txt");
  122. Ptr<MmWaveHelper> ptr_mmv = CreateObject<MmWaveHelper>();
  123.  
  124. ptr_mmv->SetAttribute("ChannelModel", StringValue("ns3::MmWave3gppChannel"));
  125. ptr_mmv->SetAttribute("PathlossModel", StringValue("ns3::MmWave3gppPropagationLossModel"));
  126.  
  127.  
  128. Ptr<NrPointToPointEpcHelper> epcHelper = CreateObject<NrPointToPointEpcHelper> ();
  129. ptr_mmv->SetEpcHelper (epcHelper);
  130. ptr_mmv->Initialize();
  131.  
  132.  
  133. // create a ue and an enb
  134. NodeContainer enb;
  135. NodeContainer ue;
  136. enb.Create(3);
  137. ue.Create(1);
  138.  
  139.  
  140. Ptr<ListPositionAllocator> enbposaloc = CreateObject<ListPositionAllocator>();
  141. enbposaloc->Add(Vector( 10, 40, 3));
  142. enbposaloc->Add(Vector( 25 , 70 , 3));
  143. enbposaloc->Add(Vector( 50, 40, 3));
  144. MobilityHelper enbmob;
  145. enbmob.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  146. enbmob.SetPositionAllocator(enbposaloc);
  147. enbmob.Install(enb);
  148.  
  149. Ptr<ListPositionAllocator> ueposaloc = CreateObject<ListPositionAllocator>();
  150. ueposaloc->Add(Vector( 60, 40, 1.5));
  151. // ueposaloc->Add(Vector( 25, 70, 1.5));
  152. //ueposaloc->Add(Vector( 149, 40.0, 1.5));
  153.  
  154. MobilityHelper uemob;
  155. uemob.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  156. uemob.SetPositionAllocator(ueposaloc);
  157. uemob.Install(ue);
  158. BuildingsHelper::Install(ue);
  159.  
  160.  
  161. NetDeviceContainer enbnetdev = ptr_mmv->InstallEnbDevice (enb);
  162. NetDeviceContainer uenetdev = ptr_mmv->InstallUeDevice (ue);
  163.  
  164. //#######################################
  165.  
  166. // create the internet and install the IP stack on the UEs
  167. // get SGW/PGW and create a single RemoteHost
  168. Ptr<Node> pgw = epcHelper->GetPgwNode ();
  169. NodeContainer remoteHostContainer;
  170. remoteHostContainer.Create (1);
  171. Ptr<Node> remoteHost = remoteHostContainer.Get (0);
  172. InternetStackHelper internet;
  173. internet.Install (remoteHostContainer);
  174.  
  175. // connect a remoteHost to pgw. Setup routing too
  176. PointToPointHelper p2ph;
  177.  
  178. p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
  179. p2ph.SetDeviceAttribute ("Mtu", UintegerValue (2500));
  180. p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.000)));
  181. NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
  182. Ipv4AddressHelper ipv4h;
  183. ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
  184. Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
  185. // in this container, interface 0 is the pgw, 1 is the remoteHost
  186. //Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
  187.  
  188. Ipv4StaticRoutingHelper ipv4RoutingHelper;
  189. Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
  190. remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
  191. internet.Install (ue);
  192. Ipv4InterfaceContainer ueIpIface;
  193. ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (uenetdev));
  194.  
  195. // Set the default gateway for the UEs
  196.  
  197. Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue.Get(0)->GetObject<Ipv4> ());
  198. //Ptr<Ipv4StaticRouting> ueStaticRouting2 = ipv4RoutingHelper.GetStaticRouting (ue.Get(1)->GetObject<Ipv4> ());
  199. //Ptr<Ipv4StaticRouting> ueStaticRouting3 = ipv4RoutingHelper.GetStaticRouting (ue.Get(2)->GetObject<Ipv4> ());
  200.  
  201. ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
  202. //ueStaticRouting2->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
  203. //ueStaticRouting3->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
  204.  
  205. // ptr_mmv->AttachToEnb (uenetdev.Get(0),enbnetdev.Get(0));
  206. // ptr_mmv->AttachToEnb (uenetdev.Get(0),enbnetdev.Get(1));
  207. // ptr_mmv->AttachToEnb (uenetdev.Get(0),enbnetdev.Get(2));
  208.  
  209.  
  210. /* uint16_t dlPort = 1234;
  211. ApplicationContainer clientAppsDl;
  212. ApplicationContainer serverAppsDl;
  213. DataRate udpRate = DataRate ("2Mbps");
  214. Time udpInterval = Time::FromDouble((1000*8) / static_cast<double> (udpRate.GetBitRate ()), Time::S);
  215.  
  216. UdpServerHelper dlPacketSinkHelper (dlPort);
  217. serverAppsDl.Add (dlPacketSinkHelper.Install (ue));
  218. */
  219. // configure UDP downlink traffic
  220. for (uint32_t i = 0 ; i < 3; i ++)
  221. {
  222.  
  223. ptr_mmv->AttachToEnb (uenetdev.Get(0),enbnetdev.Get(i));
  224.  
  225. uint16_t dlPort = 1234;
  226. ApplicationContainer clientAppsDl;
  227. ApplicationContainer serverAppsDl;
  228. DataRate udpRate = DataRate ("2Mbps");
  229. Time udpInterval = Time::FromDouble((1000*8) / static_cast<double> (udpRate.GetBitRate ()), Time::S);
  230.  
  231. UdpServerHelper dlPacketSinkHelper (dlPort);
  232. serverAppsDl.Add (dlPacketSinkHelper.Install (ue));
  233.  
  234.  
  235. UdpClientHelper dlClient (ueIpIface.GetAddress (i), dlPort); //CHECK AFTER
  236. dlClient.SetAttribute ("MaxPackets", UintegerValue(0xFFFFFFFF));
  237. dlClient.SetAttribute("PacketSize", UintegerValue(1000));
  238. 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
  239. clientAppsDl.Add (dlClient.Install (remoteHost));
  240.  
  241.  
  242.  
  243. Time udpAppStartTimeDl = NanoSeconds (100);
  244. Time udpAppStopTimeDl = NanoSeconds (500);
  245.  
  246. // start UDP server and client apps
  247. serverAppsDl.Start(udpAppStartTimeDl);
  248. clientAppsDl.Start(udpAppStartTimeDl);
  249.  
  250. serverAppsDl.Stop(udpAppStopTimeDl);
  251. clientAppsDl.Stop(udpAppStopTimeDl);
  252.  
  253. //#######################################
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260. Ptr<MmWaveSpectrumPhy> ue1SpectrumPhy1 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(0))->GetPhy(0)->GetSpectrumPhy();
  261. Ptr<mmWaveInterference> ue1SpectrumPhyInterference1 = ue1SpectrumPhy1->GetMmWaveInterference();
  262. NS_ABORT_IF(!ue1SpectrumPhyInterference1);
  263. ue1SpectrumPhyInterference1->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace1, this));
  264.  
  265. EpcUeNas Object;
  266. Object.Disconnect();
  267. }
  268.  
  269.  
  270.  
  271. /*Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy2 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(1))->GetPhy(0)->GetSpectrumPhy();
  272. Ptr<mmWaveInterference> ue1SpectrumPhyInterference2 = ue1SpectrumPhy2->GetMmWaveInterference();
  273. NS_ABORT_IF(!ue1SpectrumPhyInterference2);
  274. ue1SpectrumPhyInterference2->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace2, this));
  275.  
  276. Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy3 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(2))->GetPhy(0)->GetSpectrumPhy();
  277. Ptr<mmWaveInterference> ue1SpectrumPhyInterference3 = ue1SpectrumPhy3->GetMmWaveInterference();
  278. NS_ABORT_IF(!ue1SpectrumPhyInterference3);
  279. ue1SpectrumPhyInterference3->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace3, this));
  280. */
  281. p2ph.EnablePcapAll("x");
  282.  
  283.  
  284.  
  285. Simulator::Stop (Seconds (0.5));
  286. Simulator::Run ();
  287. Simulator::Destroy ();
  288.  
  289. }
  290.  
  291.  
  292. nr::~nr ()
  293. {
  294. cout<<"Exiting"<<endl;
  295. m_outRssiFile1.close();
  296. m_outRssiFile2.close();
  297. m_outRssiFile3.close();
  298.  
  299. }
  300.  
  301.  
  302. int main(int argc, char *argv[])
  303. {
  304. Config::SetDefault ("ns3::MmWavePhyMacCommon::CenterFreq", DoubleValue(30e9));
  305. Config::SetDefault ("ns3::MmWaveEnbPhy::TxPower", DoubleValue(23));
  306. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::ChannelCondition", StringValue("n"));
  307. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Shadowing", BooleanValue(true));
  308. Config::SetDefault ("ns3::MmWave3gppChannel::Speed", DoubleValue (3.0*1000/3600));
  309. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Scenario", StringValue("InH-ShoppingMall"));
  310. Config::SetDefault ("ns3::MmWavePhyMacCommon::MacSchedulerType", TypeIdValue (TypeId::LookupByName("ns3::MmWaveMacSchedulerTdmaPF")));
  311. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::OptionalNlos", BooleanValue(false));
  312.  
  313.  
  314. nr aa;
  315. aa.Run();
  316.  
  317. return 0;
  318.  
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement