Created
March 22, 2019 19:57
-
-
Save cawka/798b0659cbf52e35f15b2a3717091fde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ns3/lte-module.h" | |
#include "ns3/core-module.h" | |
#include "ns3/network-module.h" | |
#include "ns3/internet-module.h" | |
#include "ns3/mobility-module.h" | |
#include "ns3/applications-module.h" | |
#include "ns3/point-to-point-module.h" | |
#include "ns3/config-store.h" | |
#include <cfloat> | |
#include <sstream> | |
#include "ns3/ndnSIM-module.h" | |
using namespace ns3; | |
/* | |
* The topology is the following: | |
* | |
* UE1..........(20 m)..........UE2 | |
* (0.0, 0.0, 1.5) (20.0, 0.0, 1.5) | |
* | |
* Please refer to the Sidelink section of the LTE user documentation for more details. | |
* | |
*/ | |
NS_LOG_COMPONENT_DEFINE ("LteSlOutOfCovrg"); | |
int main (int argc, char *argv[]) | |
{ | |
Time simTime = Seconds (6); | |
bool enableNsLogs = false; | |
bool useIPv6 = false; | |
CommandLine cmd; | |
cmd.AddValue ("simTime", "Total duration of the simulation", simTime); | |
cmd.AddValue ("enableNsLogs", "Enable ns-3 logging (debug builds)", enableNsLogs); | |
cmd.AddValue ("useIPv6", "Use IPv6 instead of IPv4", useIPv6); | |
cmd.Parse (argc, argv); | |
//Configure the UE for UE_SELECTED scenario | |
Config::SetDefault ("ns3::LteUeMac::SlGrantMcs", UintegerValue (16)); | |
Config::SetDefault ("ns3::LteUeMac::SlGrantSize", UintegerValue (5)); //The number of RBs allocated per UE for Sidelink | |
Config::SetDefault ("ns3::LteUeMac::Ktrp", UintegerValue (1)); | |
Config::SetDefault ("ns3::LteUeMac::UseSetTrp", BooleanValue (true)); //use default Trp index of 0 | |
//Set the frequency | |
uint32_t ulEarfcn = 18100; | |
uint16_t ulBandwidth = 50; | |
// Set error models | |
Config::SetDefault ("ns3::LteSpectrumPhy::SlCtrlErrorModelEnabled", BooleanValue (true)); | |
Config::SetDefault ("ns3::LteSpectrumPhy::SlDataErrorModelEnabled", BooleanValue (true)); | |
Config::SetDefault ("ns3::LteSpectrumPhy::DropRbOnCollisionEnabled", BooleanValue (false)); | |
ConfigStore inputConfig; | |
inputConfig.ConfigureDefaults (); | |
// parse again so we can override input file default values via command line | |
cmd.Parse (argc, argv); | |
if (enableNsLogs) | |
{ | |
LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_PREFIX_NODE | LOG_LEVEL_ALL); | |
LogComponentEnable ("LteUeRrc", logLevel); | |
LogComponentEnable ("LteUeMac", logLevel); | |
LogComponentEnable ("LteSpectrumPhy", logLevel); | |
LogComponentEnable ("LteUePhy", logLevel); | |
} | |
//Set the UEs power in dBm | |
Config::SetDefault ("ns3::LteUePhy::TxPower", DoubleValue (23.0)); | |
//Sidelink bearers activation time | |
Time slBearersActivationTime = Seconds (2.0); | |
//Create the helpers | |
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); | |
//Create and set the EPC helper | |
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); | |
lteHelper->SetEpcHelper (epcHelper); | |
////Create Sidelink helper and set lteHelper | |
Ptr<LteSidelinkHelper> proseHelper = CreateObject<LteSidelinkHelper> (); | |
proseHelper->SetLteHelper (lteHelper); | |
//Enable Sidelink | |
lteHelper->SetAttribute ("UseSidelink", BooleanValue (true)); | |
//Set pathloss model | |
lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::Cost231PropagationLossModel")); | |
// channel model initialization | |
lteHelper->Initialize (); | |
// Since we are not installing eNB, we need to set the frequency attribute of pathloss model here | |
double ulFreq = LteSpectrumValueHelper::GetCarrierFrequency (ulEarfcn); | |
NS_LOG_LOGIC ("UL freq: " << ulFreq); | |
Ptr<Object> uplinkPathlossModel = lteHelper->GetUplinkPathlossModel (); | |
Ptr<PropagationLossModel> lossModel = uplinkPathlossModel->GetObject<PropagationLossModel> (); | |
NS_ABORT_MSG_IF (lossModel == NULL, "No PathLossModel"); | |
bool ulFreqOk = uplinkPathlossModel->SetAttributeFailSafe ("Frequency", DoubleValue (ulFreq)); | |
if (!ulFreqOk) | |
{ | |
NS_LOG_WARN ("UL propagation model does not have a Frequency attribute"); | |
} | |
NS_LOG_INFO ("Deploying UE's..."); | |
//Create nodes (UEs) | |
NodeContainer ueNodes; | |
ueNodes.Create (2); | |
NS_LOG_INFO ("UE 1 node id = [" << ueNodes.Get (0)->GetId () << "]"); | |
NS_LOG_INFO ("UE 2 node id = [" << ueNodes.Get (1)->GetId () << "]"); | |
//Position of the nodes | |
Ptr<ListPositionAllocator> positionAllocUe1 = CreateObject<ListPositionAllocator> (); | |
positionAllocUe1->Add (Vector (0.0, 0.0, 1.5)); | |
Ptr<ListPositionAllocator> positionAllocUe2 = CreateObject<ListPositionAllocator> (); | |
positionAllocUe2->Add (Vector (20.0, 0.0, 1.5)); | |
//Install mobility | |
MobilityHelper mobilityUe1; | |
mobilityUe1.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | |
mobilityUe1.SetPositionAllocator (positionAllocUe1); | |
mobilityUe1.Install (ueNodes.Get (0)); | |
MobilityHelper mobilityUe2; | |
mobilityUe2.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | |
mobilityUe2.SetPositionAllocator (positionAllocUe2); | |
mobilityUe2.Install (ueNodes.Get (1)); | |
//Install LTE UE devices to the nodes | |
NetDeviceContainer ueDevs = lteHelper->InstallUeDevice (ueNodes); | |
//Sidelink pre-configuration for the UEs | |
Ptr<LteSlUeRrc> ueSidelinkConfiguration = CreateObject<LteSlUeRrc> (); | |
ueSidelinkConfiguration->SetSlEnabled (true); | |
LteRrcSap::SlPreconfiguration preconfiguration; | |
preconfiguration.preconfigGeneral.carrierFreq = ulEarfcn; | |
preconfiguration.preconfigGeneral.slBandwidth = ulBandwidth; | |
preconfiguration.preconfigComm.nbPools = 1; | |
LteSlPreconfigPoolFactory pfactory; | |
//Control | |
pfactory.SetControlPeriod ("sf40"); | |
pfactory.SetControlBitmap (0x00000000FF); //8 subframes for PSCCH | |
pfactory.SetControlOffset (0); | |
pfactory.SetControlPrbNum (22); | |
pfactory.SetControlPrbStart (0); | |
pfactory.SetControlPrbEnd (49); | |
//Data | |
pfactory.SetDataBitmap (0xFFFFFFFFFF); | |
pfactory.SetDataOffset (8); //After 8 subframes of PSCCH | |
pfactory.SetDataPrbNum (25); | |
pfactory.SetDataPrbStart (0); | |
pfactory.SetDataPrbEnd (49); | |
preconfiguration.preconfigComm.pools[0] = pfactory.CreatePool (); | |
ueSidelinkConfiguration->SetSlPreconfiguration (preconfiguration); | |
lteHelper->InstallSidelinkConfiguration (ueDevs, ueSidelinkConfiguration); | |
InternetStackHelper internet; | |
internet.Install (ueNodes); | |
uint32_t groupL2Address = 255; | |
Ipv4Address groupAddress4 ("225.63.63.1"); //use multicast address as destination | |
Ipv4InterfaceContainer ueIpIface; | |
ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs)); | |
// set the default gateway for the UE | |
Ipv4StaticRoutingHelper ipv4RoutingHelper; | |
for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { | |
Ptr<Node> ueNode = ueNodes.Get(u); | |
// Set the default gateway for the UE | |
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv4>()); | |
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress(), 1); | |
} | |
Address remoteAddress = InetSocketAddress (groupAddress4, 8000); | |
Address localAddress = InetSocketAddress (Ipv4Address::GetAny (), 8000); | |
Ptr<LteSlTft> tft = Create<LteSlTft> (LteSlTft::BIDIRECTIONAL, groupAddress4, groupL2Address); | |
// ///*** Configure applications ***/// | |
// //Set Application in the UEs | |
// OnOffHelper sidelinkClient ("ns3::UdpSocketFactory", remoteAddress); | |
// sidelinkClient.SetConstantRate (DataRate ("16kb/s"), 200); | |
// ApplicationContainer clientApps = sidelinkClient.Install (ueNodes.Get (0)); | |
// //onoff application will send the first packet at : | |
// //(2.9 (App Start Time) + (1600 (Pkt size in bits) / 16000 (Data rate)) = 3.0 sec | |
// clientApps.Start (slBearersActivationTime + Seconds (0.9)); | |
// clientApps.Stop (simTime - slBearersActivationTime + Seconds (1.0)); | |
// ApplicationContainer serverApps; | |
// PacketSinkHelper sidelinkSink ("ns3::UdpSocketFactory", localAddress); | |
// serverApps = sidelinkSink.Install (ueNodes.Get (1)); | |
// serverApps.Start (Seconds (2.0)); | |
//Set Sidelink bearers | |
proseHelper->ActivateSidelinkBearer (slBearersActivationTime, ueDevs, tft); | |
///*** End of application configuration ***/// | |
::ns3::ndn::StackHelper helper; | |
helper.SetDefaultRoutes(true); | |
helper.InstallAll(); | |
// Consumer | |
::ns3::ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); | |
// Consumer will request /prefix/0, /prefix/1, ... | |
consumerHelper.SetPrefix("/prefix"); | |
consumerHelper.SetAttribute("Frequency", StringValue("1")); // 10 interests a second | |
consumerHelper.Install(ueNodes.Get(0)); // first node | |
// Producer | |
::ns3::ndn::AppHelper producerHelper("ns3::ndn::Producer"); | |
// Producer will reply to all requests starting with /prefix | |
producerHelper.SetPrefix("/prefix"); | |
producerHelper.SetAttribute("PayloadSize", StringValue("1024")); | |
producerHelper.Install(ueNodes.Get(1)); // last node | |
Simulator::Stop (Seconds(20)); | |
Simulator::Run (); | |
Simulator::Destroy (); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment