21 #include <ns3/core-module.h>
22 #include <ns3/network-module.h>
23 #include <ns3/mobility-module.h>
24 #include <ns3/internet-module.h>
25 #include <ns3/lte-module.h>
26 #include <ns3/config-store-module.h>
27 #include <ns3/buildings-module.h>
28 #include <ns3/point-to-point-helper.h>
29 #include <ns3/applications-module.h>
47 bool AreOverlapping (
Box a,
Box b)
49 return !((a.xMin > b.xMax) || (b.xMin > a.xMax) || (a.yMin > b.yMax) || (b.yMin > a.yMax));
56 void Create (uint32_t n);
60 bool OverlapsWithAnyPrevious (
Box);
62 uint32_t m_nApartmentsX;
64 std::list<Box> m_previousBlocks;
72 FemtocellBlockAllocator::FemtocellBlockAllocator (
Box area, uint32_t nApartmentsX, uint32_t nFloors)
74 m_nApartmentsX (nApartmentsX),
76 m_xSize (nApartmentsX*10 + 20),
79 m_xMinVar = CreateObject<UniformRandomVariable> ();
82 m_yMinVar = CreateObject<UniformRandomVariable> ();
88 FemtocellBlockAllocator::Create (uint32_t n)
90 for (uint32_t i = 0; i < n; ++i)
97 FemtocellBlockAllocator::Create ()
100 uint32_t attempt = 0;
103 NS_ASSERT_MSG (attempt < 100,
"Too many failed attemtps to position apartment block. Too many blocks? Too small area?");
105 box.xMax = box.xMin + m_xSize;
107 box.yMax = box.yMin + m_ySize;
110 while (OverlapsWithAnyPrevious (box));
112 NS_LOG_LOGIC (
"allocated non overlapping block " << box);
113 m_previousBlocks.push_back (box);
115 gridBuildingAllocator = CreateObject<GridBuildingAllocator> ();
127 gridBuildingAllocator->
Create (2);
131 FemtocellBlockAllocator::OverlapsWithAnyPrevious (
Box box)
133 for (std::list<Box>::iterator it = m_previousBlocks.begin (); it != m_previousBlocks.end (); ++it)
135 if (AreOverlapping (*it, box))
144 PrintGnuplottableBuildingListToFile (std::string filename)
146 std::ofstream outFile;
147 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
148 if (!outFile.is_open ())
154 for (BuildingList::Iterator it = BuildingList::Begin (); it != BuildingList::End (); ++it)
157 Box box = (*it)->GetBoundaries ();
158 outFile <<
"set object " << index
159 <<
" rect from " << box.xMin <<
"," << box.yMin
160 <<
" to " << box.xMax <<
"," << box.yMax
161 <<
" front fs empty "
167 PrintGnuplottableUeListToFile (std::string filename)
169 std::ofstream outFile;
170 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
171 if (!outFile.is_open ())
176 for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
180 for (
int j = 0; j < nDevs; j++)
186 outFile <<
"set label \"" << uedev->GetImsi ()
187 <<
"\" at "<< pos.
x <<
"," << pos.
y <<
" left font \"Helvetica,4\" textcolor rgb \"grey\" front point pt 1 ps 0.3 lc rgb \"grey\" offset 0,0"
195 PrintGnuplottableEnbListToFile (std::string filename)
197 std::ofstream outFile;
198 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
199 if (!outFile.is_open ())
204 for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
208 for (
int j = 0; j < nDevs; j++)
214 outFile <<
"set label \"" << enbdev->
GetCellId ()
215 <<
"\" at "<< pos.
x <<
"," << pos.
y <<
" left font \"Helvetica,4\" textcolor rgb \"white\" front point pt 2 ps 0.3 lc rgb \"white\" offset 0,0"
224 "Number of femtocell blocks",
226 ns3::MakeUintegerChecker<uint32_t> ());
228 "Number of apartments along the X axis in a femtocell block",
230 ns3::MakeUintegerChecker<uint32_t> ());
234 ns3::MakeUintegerChecker<uint32_t> ());
236 "How many macro sites there are",
238 ns3::MakeUintegerChecker<uint32_t> ());
240 "(minimum) number of sites along the X-axis of the hex grid",
242 ns3::MakeUintegerChecker<uint32_t> ());
244 "min distance between two nearby macro cell sites",
246 ns3::MakeDoubleChecker<double> ());
248 "how much the UE area extends outside the macrocell grid, "
249 "expressed as fraction of the interSiteDistance",
251 ns3::MakeDoubleChecker<double> ());
253 "How many macrocell UEs there are per square meter",
255 ns3::MakeDoubleChecker<double> ());
257 "The HeNB deployment ratio as per 3GPP R4-092042",
259 ns3::MakeDoubleChecker<double> ());
261 "The HeNB activation ratio as per 3GPP R4-092042",
263 ns3::MakeDoubleChecker<double> ());
265 "How many (on average) home UEs per HeNB there are in the simulation",
267 ns3::MakeDoubleChecker<double> ());
269 "TX power [dBm] used by macro eNBs",
271 ns3::MakeDoubleChecker<double> ());
273 "TX power [dBm] used by HeNBs",
275 ns3::MakeDoubleChecker<double> ());
277 "DL EARFCN used by macro eNBs",
279 ns3::MakeUintegerChecker<uint16_t> ());
281 "DL EARFCN used by HeNBs",
283 ns3::MakeUintegerChecker<uint16_t> ());
285 "bandwidth [num RBs] used by macro eNBs",
287 ns3::MakeUintegerChecker<uint16_t> ());
289 "bandwidth [num RBs] used by HeNBs",
291 ns3::MakeUintegerChecker<uint16_t> ());
293 "Total duration of the simulation [s]",
295 ns3::MakeDoubleChecker<double> ());
297 "if true, will generate a REM and then abort the simulation;"
298 "if false, will run the simulation normally (without generating any REM)",
300 ns3::MakeBooleanChecker ());
302 "If true, will setup the EPC to simulate an end-to-end topology, "
303 "with real IP applications over PDCP and RLC UM (or RLC AM by changing "
304 "the default value of EpsBearerToRlcMapping e.g. to RLC_AM_ALWAYS). "
305 "If false, only the LTE radio access will be simulated with RLC SM. ",
307 ns3::MakeBooleanChecker ());
309 "if true, will activate data flows in the downlink when EPC is being used. "
310 "If false, downlink flows won't be activated. "
311 "If EPC is not used, this parameter will be ignored.",
313 ns3::MakeBooleanChecker ());
315 "if true, will activate data flows in the uplink when EPC is being used. "
316 "If false, uplink flows won't be activated. "
317 "If EPC is not used, this parameter will be ignored.",
319 ns3::MakeBooleanChecker ());
321 "if true, the UdpClient application will be used. "
322 "Otherwise, the BulkSend application will be used over a TCP connection. "
323 "If EPC is not used, this parameter will be ignored.",
325 ns3::MakeBooleanChecker ());
327 "The path of the fading trace (by default no fading trace "
328 "is loaded, i.e., fading is not considered)",
330 ns3::MakeStringChecker ());
332 "How many bearers per UE there are in the simulation",
334 ns3::MakeUintegerChecker<uint16_t> ());
337 "SRS Periodicity (has to be at least greater than the number of UEs per eNB)",
339 ns3::MakeUintegerChecker<uint16_t> ());
342 main (
int argc,
char *argv[])
348 Config::SetDefault (
"ns3::UdpClient::MaxPackets",
UintegerValue(1000000));
351 cmd.
Parse (argc, argv);
353 inputConfig.ConfigureDefaults ();
355 cmd.
Parse (argc, argv);
362 GlobalValue::GetValueByName (
"nBlocks", uintegerValue);
363 uint32_t nBlocks = uintegerValue.Get ();
364 GlobalValue::GetValueByName (
"nApartmentsX", uintegerValue);
365 uint32_t nApartmentsX = uintegerValue.Get ();
366 GlobalValue::GetValueByName (
"nFloors", uintegerValue);
367 uint32_t nFloors = uintegerValue.Get ();
368 GlobalValue::GetValueByName (
"nMacroEnbSites", uintegerValue);
369 uint32_t nMacroEnbSites = uintegerValue.Get ();
370 GlobalValue::GetValueByName (
"nMacroEnbSitesX", uintegerValue);
371 uint32_t nMacroEnbSitesX = uintegerValue.Get ();
372 GlobalValue::GetValueByName (
"interSiteDistance", doubleValue);
373 double interSiteDistance = doubleValue.Get ();
374 GlobalValue::GetValueByName (
"areaMarginFactor", doubleValue);
375 double areaMarginFactor = doubleValue.Get ();
376 GlobalValue::GetValueByName (
"macroUeDensity", doubleValue);
377 double macroUeDensity = doubleValue.Get ();
378 GlobalValue::GetValueByName (
"homeEnbDeploymentRatio", doubleValue);
379 double homeEnbDeploymentRatio = doubleValue.Get ();
380 GlobalValue::GetValueByName (
"homeEnbActivationRatio", doubleValue);
381 double homeEnbActivationRatio = doubleValue.Get ();
382 GlobalValue::GetValueByName (
"homeUesHomeEnbRatio", doubleValue);
383 double homeUesHomeEnbRatio = doubleValue.Get ();
384 GlobalValue::GetValueByName (
"macroEnbTxPowerDbm", doubleValue);
385 double macroEnbTxPowerDbm = doubleValue.Get ();
386 GlobalValue::GetValueByName (
"homeEnbTxPowerDbm", doubleValue);
387 double homeEnbTxPowerDbm = doubleValue.Get ();
388 GlobalValue::GetValueByName (
"macroEnbDlEarfcn", uintegerValue);
389 uint16_t macroEnbDlEarfcn = uintegerValue.Get ();
390 GlobalValue::GetValueByName (
"homeEnbDlEarfcn", uintegerValue);
391 uint16_t homeEnbDlEarfcn = uintegerValue.Get ();
392 GlobalValue::GetValueByName (
"macroEnbBandwidth", uintegerValue);
393 uint16_t macroEnbBandwidth = uintegerValue.Get ();
394 GlobalValue::GetValueByName (
"homeEnbBandwidth", uintegerValue);
395 uint16_t homeEnbBandwidth = uintegerValue.Get ();
396 GlobalValue::GetValueByName (
"simTime", doubleValue);
397 double simTime = doubleValue.Get ();
398 GlobalValue::GetValueByName (
"epc", booleanValue);
399 bool epc = booleanValue.Get ();
400 GlobalValue::GetValueByName (
"epcDl", booleanValue);
401 bool epcDl = booleanValue.Get ();
402 GlobalValue::GetValueByName (
"epcUl", booleanValue);
403 bool epcUl = booleanValue.Get ();
404 GlobalValue::GetValueByName (
"useUdp", booleanValue);
405 bool useUdp = booleanValue.Get ();
406 GlobalValue::GetValueByName (
"generateRem", booleanValue);
407 bool generateRem = booleanValue.Get ();
408 GlobalValue::GetValueByName (
"fadingTrace", stringValue);
409 std::string fadingTrace = stringValue.Get ();
410 GlobalValue::GetValueByName (
"numBearersPerUe", uintegerValue);
411 uint16_t numBearersPerUe = uintegerValue.Get ();
412 GlobalValue::GetValueByName (
"srsPeriodicity", uintegerValue);
413 uint16_t srsPeriodicity = uintegerValue.Get ();
415 Config::SetDefault (
"ns3::LteEnbRrc::SrsPeriodicity",
UintegerValue(srsPeriodicity));
419 if (nMacroEnbSites > 0)
421 uint32_t currentSite = nMacroEnbSites -1;
422 uint32_t biRowIndex = (currentSite / (nMacroEnbSitesX + nMacroEnbSitesX + 1));
423 uint32_t biRowRemainder = currentSite % (nMacroEnbSitesX + nMacroEnbSitesX + 1);
424 uint32_t rowIndex = biRowIndex*2 + 1;
425 if (biRowRemainder >= nMacroEnbSitesX)
429 uint32_t nMacroEnbSitesY = rowIndex;
432 macroUeBox =
Box (-areaMarginFactor*interSiteDistance,
433 (nMacroEnbSitesX + areaMarginFactor)*interSiteDistance,
434 -areaMarginFactor*interSiteDistance,
435 (nMacroEnbSitesY -1)*interSiteDistance*sqrt(0.75) + areaMarginFactor*interSiteDistance,
441 macroUeBox =
Box (0, 150, 0, 150, 1.0, 2.0);
445 blockAllocator.Create (nBlocks);
448 uint32_t nHomeEnbs = round (4 * nApartmentsX * nBlocks * nFloors * homeEnbDeploymentRatio * homeEnbActivationRatio);
450 uint32_t nHomeUes = round (nHomeEnbs * homeUesHomeEnbRatio);
452 double macroUeAreaSize = (macroUeBox.xMax - macroUeBox.xMin) * (macroUeBox.yMax - macroUeBox.yMin);
453 uint32_t nMacroUes = round (macroUeAreaSize * macroUeDensity) ;
454 NS_LOG_LOGIC (
"nMacroUes = " << nMacroUes <<
" (density=" << macroUeDensity <<
")");
457 homeEnbs.
Create (nHomeEnbs);
459 macroEnbs.
Create (3 * nMacroEnbSites);
461 homeUes.
Create (nHomeUes);
463 macroUes.
Create (nMacroUes);
481 if (!fadingTrace.empty ())
491 epcHelper = CreateObject<EpcHelper> ();
503 Config::SetDefault (
"ns3::LteEnbPhy::TxPower",
DoubleValue (macroEnbTxPowerDbm));
519 Config::SetDefault (
"ns3::LteEnbPhy::TxPower",
DoubleValue (homeEnbTxPowerDbm));
529 NS_LOG_LOGIC (
"randomly allocating macro UEs in " << macroUeBox);
530 positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
533 xVal->SetAttribute (
"Max",
DoubleValue (macroUeBox.xMax));
549 positionAlloc = CreateObject<SameRoomPositionAllocator> (homeEnbs);
566 remoteHostContainer.
Create (1);
567 remoteHost = remoteHostContainer.
Get (0);
569 internet.
Install (remoteHostContainer);
579 ipv4h.
SetBase (
"1.0.0.0",
"255.0.0.0");
582 remoteHostAddr = internetIpIfaces.
GetAddress (1);
591 ueDevs.
Add (homeUeDevs);
592 ueDevs.
Add (macroUeDevs);
603 NetDeviceContainer::Iterator ueDevIt;
604 NetDeviceContainer::Iterator enbDevIt = homeEnbDevs.
Begin ();
606 for (ueDevIt = homeUeDevs.
Begin ();
607 ueDevIt != homeUeDevs.
End ();
608 ++ueDevIt, ++enbDevIt)
612 if (enbDevIt == homeEnbDevs.
End ())
614 enbDevIt = homeEnbDevs.
Begin ();
616 lteHelper->
Attach (*ueDevIt, *enbDevIt);
626 uint16_t dlPort = 10000;
627 uint16_t ulPort = 20000;
647 for (uint32_t u = 0; u < ues.
GetN (); ++u)
654 for (uint32_t b = 0; b < numBearersPerUe; ++b)
668 clientApps.
Add (dlClientHelper.Install (remoteHost));
671 serverApps.
Add (dlPacketSinkHelper.Install (ue));
677 clientApps.
Add (ulClientHelper.Install (ue));
680 serverApps.
Add (ulPacketSinkHelper.Install (remoteHost));
691 clientApps.
Add (dlClientHelper.Install (remoteHost));
694 serverApps.
Add (dlPacketSinkHelper.Install (ue));
702 clientApps.
Add (ulClientHelper.Install (ue));
705 serverApps.
Add (ulPacketSinkHelper.Install (remoteHost));
727 EpsBearer bearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT);
731 serverApps.
Start (startTime);
732 clientApps.
Start (startTime);
742 ueDevs.
Add (homeUeDevs);
743 ueDevs.
Add (macroUeDevs);
744 for (uint32_t u = 0; u < ueDevs.
GetN (); ++u)
747 for (uint32_t b = 0; b < numBearersPerUe; ++b)
756 BuildingsHelper::MakeMobilityModelConsistent ();
761 PrintGnuplottableBuildingListToFile (
"buildings.txt");
762 PrintGnuplottableEnbListToFile (
"enbs.txt");
763 PrintGnuplottableUeListToFile (
"ues.txt");
765 remHelper = CreateObject<RadioEnvironmentMapHelper> ();
780 Simulator::Stop (Seconds (simTime));
796 Simulator::Destroy ();
holds a vector of ns3::Application pointers.
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
uint8_t Add(PacketFilter f)
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
NetDeviceContainer InstallEnbDevice(NodeContainer c)
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
uint16_t GetCellId() const
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
hold variables of type string
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
#define NS_LOG_COMPONENT_DEFINE(name)
void EnableRlcTraces(void)
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
void SetLteHelper(Ptr< LteHelper > h)
Build a set of PointToPointNetDevice objects.
hold a so-called 'global value'.
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
void SetDeviceAttribute(std::string name, const AttributeValue &value)
NetDeviceContainer SetPositionAndInstallEnbDevice(NodeContainer c)
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Class for representing data rates.
void EnablePdcpTraces(void)
void AttachToClosestEnb(NetDeviceContainer ueDevices, NetDeviceContainer enbDevices)
Keep track of the current position and velocity of an object.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Create a client application which sends udp packets carrying a 32bit sequence number and a 64 bit tim...
hold objects of type ns3::Time
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
BuildingContainer Create(uint32_t n) const
Hold an unsigned integer type.
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > GetDevice(uint32_t index) const
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
#define NS_LOG_LOGIC(msg)
void SetEnbAntennaModelType(std::string type)
void SetSpectrumChannelType(std::string type)
Access to the Ipv4 forwarding table, interfaces, and configuration.
uint32_t GetNDevices(void) const
void SetFadingModelAttribute(std::string n, const AttributeValue &v)
void ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
keep track of a set of node pointers.
hold objects of type Ptr<T>
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
void SetChannelAttribute(std::string name, const AttributeValue &value)
#define NS_ASSERT_MSG(condition, message)
NetDeviceContainer InstallUeDevice(NodeContainer c)
void SetBuildingAttribute(std::string n, const AttributeValue &v)
Helper class used to assign positions and mobility models to nodes.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices)
Ipv4 addresses are stored in host order in this class.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
void SetEpcHelper(Ptr< EpcHelper > h)
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void Parse(int argc, char *argv[]) const
void SetEnbAntennaModelAttribute(std::string n, const AttributeValue &v)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnableMacTraces(void)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Hold an floating point type.
void SetAttribute(std::string name, const AttributeValue &value)
Ptr< T > GetObject(void) const
Ipv4Address GetUeDefaultGatewayAddress()
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const