Simulation script to profile simulation time

This commit is contained in:
jaumenin
2011-10-28 17:27:42 +02:00
parent 1e04a20f4c
commit d7d2733a5c
9 changed files with 289 additions and 4 deletions

View File

@@ -0,0 +1,194 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Jaume Nin <jnin@cttc.es>
*/
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/config-store.h"
#include "ns3/gtk-config-store.h"
#include <iomanip>
#include <string>
#include <vector>
using namespace ns3;
using std::vector;
int
main (int argc, char *argv[])
{
uint32_t nEnbPerFloor = 1;
uint32_t nUe = 1;
uint32_t nFloors = 0;
double simTime = 1.0;
std::string traceDirectory = "";
CommandLine cmd;
cmd.AddValue("nEnb", "Number of eNodeBs per floor", nEnbPerFloor);
cmd.AddValue("nUe", "Number of UEs", nUe);
cmd.AddValue("nFloors", "Number of floors, 0 for Friis propagation model",
nFloors);
cmd.AddValue("simTime", "Total duration of the simulation (in seconds)",
simTime);
cmd.AddValue("traceDirectory",
"Destination folder where the traces will be stored", traceDirectory);
cmd.Parse(argc, argv);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();
// parse again so you can override default values from the command line
cmd.Parse(argc, argv);
// Geometry of the scenario (in meters)
// Assume squared building
double nodeHeight = 1.5;
double roomHeight = 3;
double roomLength = 8;
uint32_t nRooms = ceil (sqrt (nEnbPerFloor));
uint32_t nEnb;
Ptr < LenaHelper > lena = CreateObject<LenaHelper> ();
lena->EnableLogComponents ();
if (nFloors == 0)
{
lena->SetAttribute("PropagationModel",
StringValue("ns3::FriisPropagationLossModel"));
nEnb = nEnbPerFloor;
}
else
{
lena->SetAttribute("PropagationModel",
StringValue("ns3::BuildingsPropagationLossModel"));
nEnb = nFloors * nEnbPerFloor;
}
// Create Nodes: eNodeB and UE
NodeContainer enbNodes;
vector < NodeContainer > ueNodes;
enbNodes.Create(nEnb);
for (uint32_t i = 0; i < nEnb; i++)
{
NodeContainer ueNode;
ueNode.Create(nUe);
ueNodes.push_back(ueNode);
}
MobilityHelper mobility;
vector<Vector> enbPosition;
Ptr < ListPositionAllocator > positionAlloc = CreateObject<ListPositionAllocator> ();
if (nFloors == 0)
{
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
// Position of eNBs
uint32_t plantedEnb = 0;
for (uint32_t row = 0; row < nRooms; row++)
{
for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++)
{
Vector v(roomLength * (column + 0.5), roomLength * (row + 0.5), nodeHeight);
positionAlloc->Add(v);
enbPosition.push_back(v);
}
}
mobility.SetPositionAllocator(positionAlloc);
mobility.Install (enbNodes);
}
else
{
Ptr < Building > building = Create<Building> (0.0, nRooms * roomLength,
0.0, nRooms * roomLength,
0.0, nFloors* roomHeight);
building->SetBuildingType(Building::Residential);
building->SetExtWallsType(Building::ConcreteWithWindows);
building->SetFloorsNumber(nFloors);
building->SetNumberRoomX(nRooms);
building->SetNumberRoomY(nRooms);
mobility.SetMobilityModel("ns3::BuildingsMobilityModel");
for (uint32_t floor = 0; floor < nFloors; floor++)
{
uint32_t plantedEnb = 0;
for (uint32_t row = 0; row < nRooms; row++)
{
for (uint32_t column = 0; column < nRooms && plantedEnb < nEnbPerFloor; column++, plantedEnb++)
{
Vector v (roomLength * (column + 0.5),
roomLength * (row + 0.5),
nodeHeight + roomHeight * floor);
positionAlloc->Add(v);
enbPosition.push_back(v);
}
}
}
mobility.SetPositionAllocator(positionAlloc);
mobility.Install (enbNodes);
}
// Position of UEs attached to eNB
for (uint32_t i = 0; i < nEnb; i++)
{
UniformVariable posX(enbPosition[i].x - roomLength * 0.5,
enbPosition[i].x + roomLength * 0.5);
UniformVariable posY(enbPosition[i].y - roomLength * 0.5,
enbPosition[i].y + roomLength * 0.5);
/* for (uint32_t j = 0; j < nUe; j++)
{*/
positionAlloc->Add(
Vector(enbPosition[i].x, enbPosition[i].y, enbPosition[i].z));
//Vector(posX.GetValue(), posY.GetValue(), nodeHeight));
//}
mobility.Install(ueNodes[i]);
}
// Create Devices and install them in the Nodes (eNB and UE)
NetDeviceContainer enbDevs;
vector < NetDeviceContainer > ueDevs;
//NetDeviceContainer ueDevs2;
enbDevs = lena->InstallEnbDevice(enbNodes);
for (uint32_t i = 0; i < nEnb; i++)
{
NetDeviceContainer ueDev = lena->InstallUeDevice(ueNodes[i]);
ueDevs.push_back(ueDev);
lena->Attach(ueDev, enbDevs.Get(i));
enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
EpsBearer bearer(q);
lena->ActivateEpsBearer(ueDev, bearer);
}
Simulator::Stop(Seconds(simTime));
lena->SetTraceDirectory(traceDirectory);
lena->EnableRlcTraces();
lena->EnableMacTraces();
Simulator::Run();
/*GtkConfigStore config;
config.ConfigureAttributes ();*/
Simulator::Destroy();
return 0;
}

View File

@@ -10,6 +10,6 @@ def build(bld):
obj = bld.create_ns3_program('lena-rlc-calculator',
['lte'])
obj.source = 'lena-rlc-calculator.cc'
obj = bld.create_ns3_program('profiling-reference',
obj = bld.create_ns3_program('lena-runtime-profiler',
['lte'])
obj.source = 'profiling-reference.cc'
obj.source = 'lena-runtime-profiler.cc'

View File

@@ -421,10 +421,10 @@ LenaHelper::EnableLogComponents (void)
LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
// LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
// LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
@@ -643,6 +643,15 @@ LenaHelper::EnableUlMacTraces (void)
MakeBoundCallback (&UlSchedulingCallback, m_macStats));
}
void
LenaHelper::SetTraceDirectory (std::string path)
{
m_macStats->SetDlOutputFilename(path + m_macStats->GetDlOutputFilename());
m_macStats->SetUlOutputFilename(path + m_macStats->GetUlOutputFilename());
m_rlcStats->SetDlOutputFilename(path + m_rlcStats->GetDlOutputFilename());
m_rlcStats->SetUlOutputFilename(path + m_rlcStats->GetUlOutputFilename());
}
Ptr<RlcStatsCalculator>
LenaHelper::GetRlcStats (void)
{

View File

@@ -183,6 +183,11 @@ public:
*/
void EnableUlRlcTraces (void);
/**
* Set the output directory for the MAC/RLC trace
*/
void SetTraceDirectory (std::string path);
Ptr<RlcStatsCalculator> GetRlcStats (void);
protected:

View File

@@ -70,12 +70,24 @@ MacStatsCalculator::SetUlOutputFilename (std::string outputFilename)
m_ulOutputFilename = outputFilename;
}
std::string
MacStatsCalculator::GetUlOutputFilename (void)
{
return m_ulOutputFilename;
}
void
MacStatsCalculator::SetDlOutputFilename (std::string outputFilename)
{
m_dlOutputFilename = outputFilename;
}
std::string
MacStatsCalculator::GetDlOutputFilename (void)
{
return m_dlOutputFilename;
}
void
MacStatsCalculator::DlScheduling (uint16_t cellId, uint64_t imsi, uint32_t frameNo, uint32_t subframeNo,
uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)

View File

@@ -66,6 +66,8 @@ public:
*/
void SetUlOutputFilename (std::string outputFilename);
std::string GetUlOutputFilename (void);
/**
* Set the name of the file where the downlink statistics will be stored.
*
@@ -73,6 +75,8 @@ public:
*/
void SetDlOutputFilename (std::string outputFilename);
std::string GetDlOutputFilename (void);
/**
* Notifies the stats calculator that an downlink scheduling has occurred.
* @param cellId Cell ID of the attached Enb

View File

@@ -105,12 +105,24 @@ RlcStatsCalculator::SetUlOutputFilename (std::string outputFilename)
m_ulOutputFilename = outputFilename;
}
std::string
RlcStatsCalculator::GetUlOutputFilename (void)
{
return m_ulOutputFilename;
}
void
RlcStatsCalculator::SetDlOutputFilename (std::string outputFilename)
{
m_dlOutputFilename = outputFilename;
}
std::string
RlcStatsCalculator::GetDlOutputFilename (void)
{
return m_dlOutputFilename;
}
void
RlcStatsCalculator::UlTxPdu (uint64_t imsi, uint16_t rnti,
uint8_t lcid, uint32_t packetSize)

View File

@@ -88,6 +88,8 @@ public:
*/
void SetUlOutputFilename (std::string outputFilename);
std::string GetUlOutputFilename (void);
/**
* Set the name of the file where the downlink statistics will be stored.
*
@@ -95,6 +97,8 @@ public:
*/
void SetDlOutputFilename (std::string outputFilename);
std::string GetDlOutputFilename (void);
/**
* Notifies the stats calculator that an uplink transmission has occurred.
* @param imsi IMSI of the UE who transmitted the PDU

View File

@@ -0,0 +1,45 @@
#!/usr/bin/perl
use strict;
use IO::CaptureOutput qw(capture qxx qxy);
use Statistics::Descriptive;
my $nIterations = 1;
open( FILE, '>times.csv' );
print FILE "#sTime\tnFloors\tnEnb\tnUe\trTime\trTDev\n";
my @nUe = ( 1, 5, 10, 15, 20, 25, 30 );
my @nEnb = ( 1, 2, 4, 6, 8, 12, 14, 18, 22 );
my @nFloors = ( 0, 1 );
#$my @simTime = ( 1, 5, 10, 20 );
my @simTime = ( 1 );
my $traceDirectory = "/home/jnin/tmp/ns-3-lena-dev/";
foreach my $time (@simTime)
{
foreach my $floor (@nFloors)
{
foreach my $enb (@nEnb)
{
foreach my $ue (@nUe)
{
my $timeStats = Statistics::Descriptive::Full->new();
for ( my $iteration = 0 ; $iteration < $nIterations ; $iteration++ )
{
my $launch = "time ./waf --run \'lena-runtime-profiler --simTime=$time --nUe=$ue --nEnb=$enb --nFloors=$floor --traceDirectory=$traceDirectory\'";
my $out, my $err;
print "$launch\n";
capture { system($launch ) } \$out, \$err;
$err =~ /real(.+)m(.+)s/;
my $minutes = $1;
my $seconds = $minutes * 60 + $2;
$timeStats->add_data($seconds);
}
print FILE "$time\t$floor\t$enb\t$ue\t";
print FILE $timeStats->mean() . "\t"
. $timeStats->standard_deviation() . "\n";
}
}
}
}