I am ns-3 beginner, and have been trying to evaluate TCP performance over LTE when user has mobility.
Even though I consider randomwalk model, I always received same mean throughput such as 1.61578 Mbps. In addition, when I checked MAC tracing file, it shows that MCS level is always same.
Furthermore, When I want to check the eNB delay, should I see the PDCP delay or RLC delay?? There are two types of delay performance in tracing.
I would like to attach my source file as follows; I would like to get your kind help or comments from.
--------------------------------------------------------------------------------------
#include <string>
#include <fstream>
#include <iomanip>
#include <ns3/log.h>
#include "ns3/point-to-point-module.h"
#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/packet-sink.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/netanim-module.h"
#include "ns3/radio-bearer-stats-calculator.h"
#include "ns3/lte-global-pathloss-database.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("LteTcpSingleFlow");
static void
CwndChange (Ptr<OutputStreamWrapper> stream, uint32_t oldCwnd, uint32_t newCwnd)
{
//NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "\t" << newCwnd);
*stream->GetStream () << Simulator::Now ().GetSeconds () << " " << newCwnd << std::endl;
}
static void
TraceCwnd ()
{
// Trace changes to the congestion window
AsciiTraceHelper ascii;
Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream ("lte-tcp-single-flow.cwnd");
Config::ConnectWithoutContext ("/NodeList/1/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeBoundCallback (&CwndChange,stream));
}
int
main (int argc, char *argv[])
{
uint32_t maxBytes = 0;
//uint32_t queueSize = 100;
DataRate linkRate("1Gbps");
std::string protocol = "TcpNewReno";
double simTime = 5.0;
CommandLine cmd;
//cmd.AddValue("queueSize","queue size",queueSize);
cmd.AddValue("linkRate","link rate",linkRate);
cmd.AddValue("protocol","protocol",protocol);
cmd.Parse(argc,argv);
// Set TCP defaults
Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue (1460));
Config::SetDefault("ns3::TcpSocket::DelAckCount", UintegerValue (0));
// Config::SetDefault("ns3::TcpSocket::SndBufSize", UintegerValue (524288));
// Config::SetDefault("ns3::TcpSocket::RcvBufSize", UintegerValue (524288));
// Config::SetDefault("ns3::TcpSocket::SlowStartThreshold", UintegerValue (1000000));
if (protocol == "TcpTahoe")
Config::SetDefault("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpTahoe"));
else
Config::SetDefault("ns3::TcpL4Protocol::SocketType", StringValue("ns3::TcpNewReno"));
FlowMonitorHelper fl;
Ptr<FlowMonitor> monitor;
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::Cost231PropagationLossModel"));
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();
// parse again so you can override default values from the command line
cmd.Parse(argc, argv);
Ptr<Node> pgw = epcHelper->GetPgwNode ();
// Create a single RemoteHost
NodeContainer remoteHostContainer;
remoteHostContainer.Create (1);
Ptr<Node> remoteHost = remoteHostContainer.Get (0);
// Create the Internet
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (linkRate)));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
//p2ph.SetQueue("ns3::DropTailQueue","MaxPackets",UintegerValue(queueSize));
p2ph.SetChannelAttribute ("Delay", StringValue ("1ms"));
NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
// Install the internet stack on the nodes
InternetStackHelper internet;
internet.Install (remoteHostContainer);
Ipv4AddressHelper ipv4h;
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
// interface 0 is localhost, 1 is the p2p device
Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
NodeContainer ueNodes;
NodeContainer enbNodes;
enbNodes.Create(1);
ueNodes.Create(1);
// Install Static Mobility Model
// Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
// positionAlloc->Add (Vector(0, 0, 0));
// MobilityHelper mobility;
//mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
//mobility.SetPositionAllocator(positionAlloc);
//mobility.Install(enbNodes);
//mobility.Install(ueNodes);
// Position of eNBs
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
MobilityHelper enbMobility;
enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
enbMobility.SetPositionAllocator (positionAlloc);
enbMobility.Install (enbNodes);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel","Bounds", RectangleValue (Rectangle (-1000, 1000, -1000, 1000)));
mobility.Install (ueNodes);
MobilityHelper mobility2;
mobility2.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility2.Install (pgw);
mobility2.Install (remoteHost);
// Install LTE Devices to the nodes
NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
// Install the IP stack on the UEs
internet.Install (ueNodes);
Ipv4InterfaceContainer ueIpIface;
ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
// Assign IP address to UEs, and install applications
Ptr<Node> ueNode = ueNodes.Get (0);
// Set the default gateway for the UE
Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
// Attach one UE per eNodeB
lteHelper->Attach (ueLteDevs.Get(0), enbLteDevs.Get(0));
// Create a BulkSendApplication and install it on remote host
uint16_t port = 8080; // well-known echo port number
BulkSendHelper source ("ns3::TcpSocketFactory",
InetSocketAddress (ueIpIface.GetAddress (0), port));
// Set the amount of data to send in bytes. Zero is unlimited.
source.SetAttribute ("MaxBytes", UintegerValue (maxBytes));
// Set the segment size
source.SetAttribute ("SendSize", UintegerValue (1000));
ApplicationContainer sourceApps = source.Install (remoteHostContainer.Get (0));
sourceApps.Start (Seconds (0.0));
sourceApps.Stop (Seconds (simTime));
// Create a PacketSinkApplication and install it on ueNode
Address sinkAddress (InetSocketAddress (ueIpIface.GetAddress (0), port));
PacketSinkHelper sink ("ns3::TcpSocketFactory",
InetSocketAddress (Ipv4Address::GetAny (), port));
ApplicationContainer sinkApps = sink.Install (ueNodes.Get (0));
sinkApps.Start (Seconds (0.0));
sinkApps.Stop (Seconds (simTime));
// Set up tracing
AsciiTraceHelper ascii;
p2ph.EnablePcapAll ("lte-tcp-single-flow", false);
// Setup tracing for cwnd
Simulator::Schedule(Seconds(0.00001),&TraceCwnd);
Simulator::Stop (Seconds (simTime));
// monitor = fl.Install(enbNodes);
// monitor->SetAttribute ("DelayBinWidth", DoubleValue(0.001));
// monitor->SetAttribute ("JitterBinWidth", DoubleValue(0.001));
// monitor->SetAttribute ("PacketSizeBinWidth", DoubleValue(20));
lteHelper->EnablePdcpTraces ();
lteHelper->EnableMacTraces ();
lteHelper->EnableRlcTraces ();
lteHelper->EnablePhyTraces ();
// Run the simulation
Simulator::Run ();
Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sinkApps.Get (0));
std::cout << "Total Bytes Received (Byte): " << sink1->GetTotalRx () << std::endl;
std::cout << "Total Throughput (Mbps): " << sink1->GetTotalRx ()*8/simTime/1000000 << std::endl;
Simulator::Destroy ();
}