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