5G-LENA nr-v3.0-33-g7aea1e4
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
three-gpp-ftp-m1-helper.cc
1/* Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; */
2
3// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "three-gpp-ftp-m1-helper.h"
8
9#include <ns3/packet-sink-helper.h>
10#include <ns3/traffic-generator-ftp-single.h>
11
12namespace ns3
13{
14
15NS_LOG_COMPONENT_DEFINE("ThreeGppFtpM1Helper");
16
17ThreeGppFtpM1Helper::ThreeGppFtpM1Helper(ApplicationContainer* serverApps,
18 ApplicationContainer* clientApps,
19 NodeContainer* serverNodes,
20 NodeContainer* clientNodes,
21 Ipv4InterfaceContainer* serversIps)
22{
23 NS_LOG_FUNCTION(this);
24 m_serverApps = serverApps;
25 m_clientApps = clientApps;
26 m_serverNodes = serverNodes;
27 m_clientNodes = clientNodes;
28 m_serversIps = serversIps;
29}
30
32{
33 NS_LOG_FUNCTION(this);
34}
35
37{
38 NS_LOG_FUNCTION(this);
39}
40
41TypeId
43{
44 static TypeId tid = TypeId("ns3::ThreeGppFtpM1Helper")
45 .SetParent<Object>()
46 .AddConstructor<ThreeGppFtpM1Helper>();
47 return tid;
48}
49
50void
51ThreeGppFtpM1Helper::DoConfigureFtpServers()
52{
53 NS_LOG_FUNCTION(this);
54 Address apLocalAddress(InetSocketAddress(Ipv4Address::GetAny(), m_port));
55 PacketSinkHelper packetSinkHelper("ns3::UdpSocketFactory", apLocalAddress);
56 *m_serverApps = packetSinkHelper.Install(*m_serverNodes);
57 m_serverApps->Start(m_serverStartTime);
58}
59
60void
61ThreeGppFtpM1Helper::DoConfigureFtpClients()
62{
63 NS_LOG_FUNCTION(this);
64 uint32_t ftpSegSize = 1448; // bytes
65 TrafficGeneratorHelper ftpHelper("ns3::UdpSocketFactory",
66 Address(),
68 ftpHelper.SetAttribute("PacketSize", UintegerValue(ftpSegSize));
69 ftpHelper.SetAttribute("FileSize", UintegerValue(m_ftpFileSize));
70
71 for (uint32_t i = 0; i < m_serversIps->GetN(); i++)
72 {
73 Ipv4Address ipAddress = m_serversIps->GetAddress(i, 0);
74 AddressValue remoteAddress(InetSocketAddress(ipAddress, m_port));
75 ftpHelper.SetAttribute("Remote", remoteAddress);
76 m_clientApps->Add(ftpHelper.Install(*m_clientNodes));
77
78 // Seed the ARP cache by pinging early in the simulation
79 // This is a workaround until a static ARP capability is provided
80 PingHelper ping(ipAddress);
81 m_pingApps.Add(ping.Install(*m_clientNodes));
82 }
83
84 m_clientApps->Start(m_clientStartTime + Seconds(m_startJitter->GetValue()));
85 // Add one or two pings for ARP at the beginning of the simulation
86 m_pingApps.Start(Seconds(0.300) + Seconds(m_startJitter->GetValue()));
87 m_pingApps.Stop(Seconds(0.500));
88}
89
90void
91ThreeGppFtpM1Helper::DoStartFileTransfer()
92{
93 NS_LOG_FUNCTION(this);
94 NS_ASSERT(m_lastClient >= 0 && m_lastClient < m_clientApps->GetN());
95 Ptr<Application> app = m_clientApps->Get(m_lastClient);
96 NS_ASSERT(app);
97 Ptr<TrafficGenerator> fileTransfer = DynamicCast<TrafficGenerator>(app);
98 NS_ASSERT(fileTransfer);
99 fileTransfer->SendPacketBurst();
100
101 m_lastClient += 1;
102 if (m_lastClient == m_clientApps->GetN())
103 {
104 m_lastClient = 0;
105 }
106 Simulator::Schedule(DoGetNextTime(), &ThreeGppFtpM1Helper::DoStartFileTransfer, this);
107}
108
109void
111 Time serverStartTime,
112 Time clientStartTime,
113 Time clientStopTime,
114 double ftpLambda,
115 uint32_t ftpFileSize)
116{
117 NS_LOG_FUNCTION(this);
118 NS_ABORT_MSG_IF(m_boolConfigured, "Already configured FTP M1 helper.");
119 NS_ABORT_MSG_IF(m_serverNodes->GetN() == 0 || m_clientNodes->GetN() == 0 ||
120 m_serversIps->GetN() == 0,
121 "Server and/or client nodes or IP server interfaces not set.");
122 m_port = port;
123 m_clientStartTime = clientStartTime;
124 m_clientStopTime = clientStopTime;
125 m_ftpLambda = ftpLambda;
126 m_ftpFileSize = ftpFileSize;
127 m_serverStartTime = serverStartTime;
128 m_boolConfigured = true;
129
130 m_ftpArrivals = CreateObject<ExponentialRandomVariable>();
131 m_ftpArrivals->SetAttribute("Mean", DoubleValue(1 / m_ftpLambda));
132 // Randomly distribute the start times across 100ms interval
133 m_startJitter = CreateObject<UniformRandomVariable>();
134 m_startJitter->SetAttribute("Max", DoubleValue(0.100));
135}
136
137void
139{
140 NS_LOG_FUNCTION(this);
141 NS_ASSERT(m_boolConfigured);
142
143 DoConfigureFtpServers();
144 DoConfigureFtpClients();
145
146 // Start file transfer arrival process in both networks
147 Simulator::Schedule(m_clientStartTime + DoGetNextTime(),
148 &ThreeGppFtpM1Helper::DoStartFileTransfer,
149 this);
150}
151
152Time
153ThreeGppFtpM1Helper::DoGetNextTime() const
154{
155 return Seconds(m_ftpArrivals->GetValue());
156}
157
158int64_t
160{
161 m_ftpArrivals->SetStream(stream);
162 m_startJitter->SetStream(stream + 1);
163
164 return 2;
165}
166
167} // namespace ns3
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.