5#include "three-gpp-ftp-m1-helper.h"
7#include <ns3/packet-sink-helper.h>
8#include <ns3/traffic-generator-ftp-single.h>
13NS_LOG_COMPONENT_DEFINE(
"ThreeGppFtpM1Helper");
16 ApplicationContainer* clientApps,
17 NodeContainer* serverNodes,
18 NodeContainer* clientNodes,
19 Ipv4InterfaceContainer* serversIps)
21 NS_LOG_FUNCTION(
this);
22 m_serverApps = serverApps;
23 m_clientApps = clientApps;
24 m_serverNodes = serverNodes;
25 m_clientNodes = clientNodes;
26 m_serversIps = serversIps;
31 NS_LOG_FUNCTION(
this);
36 NS_LOG_FUNCTION(
this);
42 static TypeId tid = TypeId(
"ns3::ThreeGppFtpM1Helper")
44 .AddConstructor<ThreeGppFtpM1Helper>();
49ThreeGppFtpM1Helper::DoConfigureFtpServers()
51 NS_LOG_FUNCTION(
this);
52 Address apLocalAddress(InetSocketAddress(Ipv4Address::GetAny(), m_port));
53 PacketSinkHelper packetSinkHelper(
"ns3::UdpSocketFactory", apLocalAddress);
54 *m_serverApps = packetSinkHelper.Install(*m_serverNodes);
55 m_serverApps->Start(m_serverStartTime);
59ThreeGppFtpM1Helper::DoConfigureFtpClients()
61 NS_LOG_FUNCTION(
this);
62 uint32_t ftpSegSize = 1448;
63 TrafficGeneratorHelper ftpHelper(
"ns3::UdpSocketFactory",
66 ftpHelper.SetAttribute(
"PacketSize", UintegerValue(ftpSegSize));
67 ftpHelper.SetAttribute(
"FileSize", UintegerValue(m_ftpFileSize));
69 for (uint32_t i = 0; i < m_serversIps->GetN(); i++)
71 Ipv4Address ipAddress = m_serversIps->GetAddress(i, 0);
72 AddressValue remoteAddress(InetSocketAddress(ipAddress, m_port));
73 ftpHelper.SetAttribute(
"Remote", remoteAddress);
74 m_clientApps->Add(ftpHelper.Install(*m_clientNodes));
78 PingHelper ping(ipAddress);
79 m_pingApps.Add(ping.Install(*m_clientNodes));
82 m_clientApps->Start(m_clientStartTime + Seconds(m_startJitter->GetValue()));
84 m_pingApps.Start(Seconds(0.300) + Seconds(m_startJitter->GetValue()));
85 m_pingApps.Stop(Seconds(0.500));
89ThreeGppFtpM1Helper::DoStartFileTransfer()
91 NS_LOG_FUNCTION(
this);
92 NS_ASSERT(m_lastClient >= 0 && m_lastClient < m_clientApps->GetN());
93 Ptr<Application> app = m_clientApps->Get(m_lastClient);
95 Ptr<TrafficGenerator> fileTransfer = DynamicCast<TrafficGenerator>(app);
96 NS_ASSERT(fileTransfer);
97 fileTransfer->SendPacketBurst();
100 if (m_lastClient == m_clientApps->GetN())
104 Simulator::Schedule(DoGetNextTime(), &ThreeGppFtpM1Helper::DoStartFileTransfer,
this);
109 Time serverStartTime,
110 Time clientStartTime,
113 uint32_t ftpFileSize)
115 NS_LOG_FUNCTION(
this);
116 NS_ABORT_MSG_IF(m_boolConfigured,
"Already configured FTP M1 helper.");
117 NS_ABORT_MSG_IF(m_serverNodes->GetN() == 0 || m_clientNodes->GetN() == 0 ||
118 m_serversIps->GetN() == 0,
119 "Server and/or client nodes or IP server interfaces not set.");
121 m_clientStartTime = clientStartTime;
122 m_clientStopTime = clientStopTime;
123 m_ftpLambda = ftpLambda;
124 m_ftpFileSize = ftpFileSize;
125 m_serverStartTime = serverStartTime;
126 m_boolConfigured =
true;
128 m_ftpArrivals = CreateObject<ExponentialRandomVariable>();
129 m_ftpArrivals->SetAttribute(
"Mean", DoubleValue(1 / m_ftpLambda));
131 m_startJitter = CreateObject<UniformRandomVariable>();
132 m_startJitter->SetAttribute(
"Max", DoubleValue(0.100));
138 NS_LOG_FUNCTION(
this);
139 NS_ASSERT(m_boolConfigured);
141 DoConfigureFtpServers();
142 DoConfigureFtpClients();
145 Simulator::Schedule(m_clientStartTime + DoGetNextTime(),
146 &ThreeGppFtpM1Helper::DoStartFileTransfer,
151ThreeGppFtpM1Helper::DoGetNextTime()
const
153 return Seconds(m_ftpArrivals->GetValue());
159 m_ftpArrivals->SetStream(stream);
160 m_startJitter->SetStream(stream + 1);
~ThreeGppFtpM1Helper() override
static TypeId GetTypeId()
GetTypeId.
void Start()
Start to generate file transfers according to FTP Model 1.
void Configure(uint16_t port, Time serverStartTime, Time clientStartTime, Time clientStopTime, double ftpLambda, uint32_t ftpFileSize)
To be called before Start() function.
int64_t AssignStreams(int64_t stream)
static TypeId GetTypeId()
Get the type ID.