Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.89 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(3);
  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(1),enbnetdev.Get(1));
  207. ptr_mmv->AttachToEnb (uenetdev.Get(2),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. // configure UDP downlink traffic
  219. for (uint32_t i = 0 ; i < 3; i ++)
  220. {
  221. UdpClientHelper dlClient (ueIpIface.GetAddress (i), dlPort); //CHECK AFTER
  222. dlClient.SetAttribute ("MaxPackets", UintegerValue(0xFFFFFFFF));
  223. dlClient.SetAttribute("PacketSize", UintegerValue(1000));
  224. 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
  225. clientAppsDl.Add (dlClient.Install (remoteHost));}
  226.  
  227. Time udpAppStartTimeDl = MilliSeconds (100);
  228. Time udpAppStopTimeDl = MilliSeconds (500);
  229.  
  230. // start UDP server and client apps
  231. serverAppsDl.Start(udpAppStartTimeDl);
  232. clientAppsDl.Start(udpAppStartTimeDl);
  233.  
  234. serverAppsDl.Stop(udpAppStopTimeDl);
  235. clientAppsDl.Stop(udpAppStopTimeDl);
  236.  
  237. //#######################################
  238.  
  239.  
  240.  
  241. Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy1 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(0))->GetPhy(0)->GetSpectrumPhy();
  242. Ptr<mmWaveInterference> ue1SpectrumPhyInterference1 = ue1SpectrumPhy1->GetMmWaveInterference();
  243. NS_ABORT_IF(!ue1SpectrumPhyInterference1);
  244. ue1SpectrumPhyInterference1->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace1, this));
  245.  
  246.  
  247. Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy2 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(1))->GetPhy(0)->GetSpectrumPhy();
  248. Ptr<mmWaveInterference> ue1SpectrumPhyInterference2 = ue1SpectrumPhy2->GetMmWaveInterference();
  249. NS_ABORT_IF(!ue1SpectrumPhyInterference2);
  250. ue1SpectrumPhyInterference2->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace2, this));
  251.  
  252. Ptr<MmWaveSpectrumPhy > ue1SpectrumPhy3 = DynamicCast<MmWaveUeNetDevice> (uenetdev.Get(2))->GetPhy(0)->GetSpectrumPhy();
  253. Ptr<mmWaveInterference> ue1SpectrumPhyInterference3 = ue1SpectrumPhy3->GetMmWaveInterference();
  254. NS_ABORT_IF(!ue1SpectrumPhyInterference3);
  255. ue1SpectrumPhyInterference3->TraceConnectWithoutContext("RssiPerProcessedChunk", MakeBoundCallback (&UeRssiPerProcessedChunkTrace3, this));
  256.  
  257. p2ph.EnablePcapAll("x");
  258.  
  259.  
  260. AnimationInterface anim("Res.xml");
  261. anim.SetConstantPosition(ue.Get(0), 60, 40, 1.5);
  262. anim.SetConstantPosition(ue.Get(1), 25, 70, 1.5);
  263. anim.SetConstantPosition(ue.Get(2), 149, 40.0, 1.5);
  264. anim.SetConstantPosition(enb.Get(0), 10, 40, 3);
  265. anim.SetConstantPosition(enb.Get(1), 25 , 70 , 3);
  266. anim.SetConstantPosition(enb.Get(2), 50, 40, 3);
  267.  
  268.  
  269.  
  270. Simulator::Stop (Seconds (0.5));
  271. Simulator::Run ();
  272. Simulator::Destroy ();
  273.  
  274. }
  275.  
  276.  
  277. nr::~nr ()
  278. {
  279. cout<<"Exiting"<<endl;
  280. m_outRssiFile1.close();
  281. m_outRssiFile2.close();
  282. m_outRssiFile3.close();
  283.  
  284. }
  285.  
  286.  
  287. int main(int argc, char *argv[])
  288. {
  289. Config::SetDefault ("ns3::MmWavePhyMacCommon::CenterFreq", DoubleValue(30e9));
  290. Config::SetDefault ("ns3::MmWaveEnbPhy::TxPower", DoubleValue(23));
  291. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::ChannelCondition", StringValue("n"));
  292. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Shadowing", BooleanValue(true));
  293. Config::SetDefault ("ns3::MmWave3gppChannel::Speed", DoubleValue (3.0*1000/3600));
  294. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::Scenario", StringValue("InH-ShoppingMall"));
  295. Config::SetDefault ("ns3::MmWavePhyMacCommon::MacSchedulerType", TypeIdValue (TypeId::LookupByName("ns3::MmWaveMacSchedulerTdmaPF")));
  296. Config::SetDefault ("ns3::MmWave3gppPropagationLossModel::OptionalNlos", BooleanValue(false));
  297.  
  298.  
  299. nr aa;
  300. aa.Run();
  301.  
  302. return 0;
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement