Académique Documents
Professionnel Documents
Culture Documents
#include "ns3/lte-helper.h"
#include "ns3/epc-helper.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/applications-module.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/config-store.h"
#include <ns3/buildings-module.h>
#include "ns3/netanim-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/log.h"
#include <sys/timeb.h>
#include <ns3/internet-trace-helper.h>
#include <ns3/spectrum-module.h>
#include <ns3/log.h>
#include <ns3/string.h>
#include <fstream>
void
PrintGnuplottableUeListToFile (std::string filename)
{
std::ofstream outFile;
outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!outFile.is_open ())
{
NS_LOG_ERROR ("Can't open file " << filename);
return;
}
for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
{
Ptr<Node> node = *it;
int nDevs = node->GetNDevices ();
for (int j = 0; j < nDevs; j++)
{
Ptr<LteUeNetDevice> uedev = node->GetDevice (j)->GetObject
<LteUeNetDevice> ();
if (uedev)
{
Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
outFile << "set label \"" << uedev->GetImsi ()
<< "\" 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"
<< std::endl;
}
}
}
}
void
PrintGnuplottableEnbListToFile (std::string filename)
{
std::ofstream outFile;
outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
if (!outFile.is_open ())
{
NS_LOG_ERROR ("Can't open file " << filename);
return;
}
for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
{
Ptr<Node> node = *it;
int nDevs = node->GetNDevices ();
for (int j = 0; j < nDevs; j++)
{
Ptr<LteEnbNetDevice> enbdev = node->GetDevice (j)->GetObject
<LteEnbNetDevice> ();
if (enbdev)
{
Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
outFile << "set label \"" << enbdev->GetCellId ()
<< "\" 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"
<< std::endl;
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
AnimationInterface * pAnim = 0;
struct rgb {
uint8_t r;
uint8_t g;
uint8_t b;
};
void modify ()
{
std::ostringstream oss;
oss << "Update:" << Simulator::Now ().GetSeconds ();
pAnim->UpdateLinkDescription (0, 1, oss.str ());
pAnim->UpdateLinkDescription (0, 2, oss.str ());
pAnim->UpdateLinkDescription (0, 3, oss.str ());
pAnim->UpdateLinkDescription (0, 4, oss.str ());
pAnim->UpdateLinkDescription (0, 5, oss.str ());
pAnim->UpdateLinkDescription (0, 6, oss.str ());
pAnim->UpdateLinkDescription (1, 7, oss.str ());
pAnim->UpdateLinkDescription (1, 8, oss.str ());
pAnim->UpdateLinkDescription (1, 9, oss.str ());
pAnim->UpdateLinkDescription (1, 10, oss.str ());
pAnim->UpdateLinkDescription (1, 11, oss.str ());
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
uint16_t numberOfNodesENB = 3;
uint16_t numberOfNodesEU = 10;
double simTime = 0.05;
double distance = 250.0;
double interPacketInterval = 150.0;
CommandLine cmd;
cmd.AddValue("numberOfNodes", "Number of eNodeBs + UE pairs", numberOfNodesENB);
cmd.AddValue("simTime", "Total duration of the simulation [s])", simTime);
cmd.AddValue("distance", "Distance between eNBs [m]", distance);
cmd.AddValue("interPacketInterval", "Inter packet interval [ms])",
interPacketInterval);
cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
cmd.Parse (argc, argv);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults ();
cmd.Parse (argc, argv);
std::ifstream ifTraceFile;
ifTraceFile.open ("src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad",
std::ifstream::in);
if (ifTraceFile.good ())
{
// script launched by test.py
lteHelper->SetFadingModelAttribute ("TraceFilename", StringValue
("src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
}
else
{
// script launched as an example
lteHelper->SetFadingModelAttribute ("TraceFilename", StringValue
("src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
}
// creation RemoteHost .
NodeContainer remoteHostContainer;
remoteHostContainer.Create (1);
Ptr<Node> remoteHost = remoteHostContainer.Get (0);
InternetStackHelper internet;
internet.Install (remoteHostContainer);
Ptr<ListPositionAllocator> positionAlloc1 =
CreateObject<ListPositionAllocator>();
positionAlloc1->Add(Vector(500.0, -100.0, 20.0));
MobilityHelper mobility1;
mobility1.SetPositionAllocator (positionAlloc1);
mobility1.Install (remoteHostContainer);
// Create the Internet
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("150Mb/s")));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
Ipv4AddressHelper ipv4h;
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask
("255.0.0.0"), 1);
//creation des noeuds pour eNB et UE
NodeContainer enbNodes;
enbNodes.Create (numberOfNodesENB);
NodeContainer ueNodes;
ueNodes.Create (numberOfNodesEU);
Ptr<GridBuildingAllocator> gridBuildingAllocator;
gridBuildingAllocator = CreateObject<GridBuildingAllocator> ();
gridBuildingAllocator->SetAttribute ("GridWidth", UintegerValue (3));
gridBuildingAllocator->SetAttribute ("LengthX", DoubleValue (7));
gridBuildingAllocator->SetAttribute ("LengthY", DoubleValue (13));
gridBuildingAllocator->SetAttribute ("DeltaX", DoubleValue (3));
gridBuildingAllocator->SetAttribute ("DeltaY", DoubleValue (3));
gridBuildingAllocator->SetAttribute ("Height", DoubleValue (6));
gridBuildingAllocator->SetBuildingAttribute ("NRoomsX", UintegerValue (2));
gridBuildingAllocator->SetBuildingAttribute ("NRoomsY", UintegerValue (4));
gridBuildingAllocator->SetBuildingAttribute ("NFloors", UintegerValue (2));
gridBuildingAllocator->SetAttribute ("MinX", DoubleValue (0));
gridBuildingAllocator->SetAttribute ("MinY", DoubleValue (0));
gridBuildingAllocator->Create (6);
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator("ns3::GridPositionAllocator",
"MinX", DoubleValue (-350.0),
"MinY", DoubleValue (-200.0),
"DeltaX", DoubleValue (0.0),
"DeltaY", DoubleValue (150.0),
"GridWidth", UintegerValue (1),
"LayoutType", StringValue ("RowFirst"));
mobility.Install (enbNodes);
BuildingsHelper::Install (enbNodes);
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Mode", StringValue ("Time"),
"Time", StringValue ("0.5s"),
"Speed", StringValue
("ns3::ConstantRandomVariable[Constant=50.0]"),
"Bounds", RectangleValue (Rectangle (-12000.0, 12000.0,
-12000.0, 12000.0)));
}
mobility.Install (ueNodes);
AsciiTraceHelper ascii;
MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("mobility-trace-
example.mob"));
//pour activer le support radio qui porte les donn�es entre ueDevs et enbDevs
Ptr<EpcTft> tft = Create<EpcTft> ();
EpcTft::PacketFilter pf;
pf.localPortStart = 1234;
pf.localPortEnd = 1234;
tft->Add (pf);
lteHelper->ActivateDedicatedEpsBearer (ueDevs, EpsBearer
(EpsBearer::NGBR_VIDEO_TCP_DEFAULT), tft);
lteHelper->EnablePhyTraces ();
lteHelper->EnableMacTraces ();
lteHelper->EnableRlcTraces ();
Simulator::Run ();
Simulator::Destroy ();
delete pAnim;
return 0;