13#include "ns3/config.h"
14#include "ns3/core-module.h"
15#include "ns3/inet-socket-address.h"
16#include "ns3/internet-stack-helper.h"
17#include "ns3/ipv4-address-helper.h"
18#include "ns3/ipv4-global-routing-helper.h"
20#include "ns3/packet-sink-helper.h"
21#include "ns3/packet-sink.h"
22#include "ns3/ping-helper.h"
23#include "ns3/simple-channel.h"
24#include "ns3/simple-net-device.h"
25#include "ns3/simulator.h"
26#include "ns3/traffic-generator-ftp-single.h"
27#include "ns3/traffic-generator-helper.h"
28#include "ns3/traffic-generator-ngmn-ftp-multi.h"
29#include "ns3/traffic-generator-ngmn-gaming.h"
30#include "ns3/traffic-generator-ngmn-video.h"
31#include "ns3/traffic-generator-ngmn-voip.h"
46static inline std::istream&
47operator>>(std::istream& is, TrafficType& item)
51 item = (TrafficType)inputValue;
56GetTypeId(
const TrafficType& item)
69 NS_ABORT_MSG(
"Unknown traffic type");
74GetName(
const TrafficType& item)
87 NS_ABORT_MSG(
"Unknown traffic type");
92WriteBytesSent(Ptr<TrafficGenerator> trafficGenerator,
93 uint64_t* previousBytesSent,
94 uint64_t* previousWindowBytesSent,
95 enum TrafficType trafficType,
96 std::ofstream* outFileTx)
98 uint64_t totalBytesSent = trafficGenerator->GetTotalBytes();
100 << Simulator::Now().GetMilliSeconds() <<
"\t" << *previousWindowBytesSent
103 << Simulator::Now().GetMilliSeconds() <<
"\t"
104 << totalBytesSent - *previousBytesSent << std::endl;
106 *previousWindowBytesSent = totalBytesSent - *previousBytesSent;
107 *previousBytesSent = totalBytesSent;
111WriteBytesReceived(Ptr<PacketSink> packetSink, uint64_t* previousBytesReceived)
113 uint64_t totalBytesReceived = packetSink->GetTotalRx();
114 *previousBytesReceived = totalBytesReceived;
118main(
int argc,
char* argv[])
120 enum TrafficType trafficType = NGMN_FTP;
122 uint32_t measWindowMs = 10;
123 uint32_t appStartMs = 500;
124 uint32_t appDurationMs = 100;
126 CommandLine cmd(__FILE__);
127 cmd.AddValue(
"trafficType",
128 "The traffic type to be configured. Currently the following options are "
129 "available: 0 (ftp), 1 (video), 2 (gaming) and 3 (voip).",
131 cmd.AddValue(
"useUdp",
132 "if true, the NGMN applications will run over UDP connection, otherwise a TCP "
133 "connection will be used. ",
135 cmd.AddValue(
"appStartMs",
"Application start time in ms, greater than 500", appStartMs);
136 cmd.AddValue(
"appDurationMs",
137 "Application duration time in ms, greater than 100",
139 cmd.AddValue(
"measWindowMs",
"Measurement window time in ms, greathen than 10", measWindowMs);
141 cmd.Parse(argc, argv);
143 NS_ASSERT(appStartMs >= 500);
144 NS_ASSERT(appDurationMs >= 100);
145 NS_ASSERT(measWindowMs >= 10);
148 std::string transportProtocol;
151 transportProtocol =
"ns3::UdpSocketFactory";
155 transportProtocol =
"ns3::TcpSocketFactory";
160 InternetStackHelper internet;
161 internet.Install(nodes);
163 Ptr<SimpleNetDevice> txDev = CreateObject<SimpleNetDevice>();
164 Ptr<SimpleNetDevice> rxDev = CreateObject<SimpleNetDevice>();
165 nodes.Get(0)->AddDevice(txDev);
166 nodes.Get(1)->AddDevice(rxDev);
167 Ptr<SimpleChannel> channel1 = CreateObject<SimpleChannel>();
168 rxDev->SetChannel(channel1);
169 txDev->SetChannel(channel1);
170 NetDeviceContainer devices;
173 Ipv4AddressHelper ipv4;
174 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
175 Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign(devices);
178 uint16_t port = 4000;
179 InetSocketAddress rxAddress(Ipv4Address::GetAny(), port);
181 PacketSinkHelper packetSinkHelper(transportProtocol, rxAddress);
184 ApplicationContainer sinkApplication = packetSinkHelper.Install(nodes.Get(1));
185 sinkApplication.Start(MilliSeconds(appStartMs));
186 sinkApplication.Stop(MilliSeconds(appStartMs + appDurationMs));
191 InetSocketAddress(ipv4Interfaces.GetAddress(1, 0), port),
192 GetTypeId(trafficType));
194 ApplicationContainer generatorApplication = trafficGeneratorHelper.Install(nodes.Get(0));
195 generatorApplication.Start(MilliSeconds(appStartMs));
196 generatorApplication.Stop(MilliSeconds(appStartMs + appDurationMs));
200 PingHelper pingHelper(ipv4Interfaces.GetAddress(1, 0));
201 ApplicationContainer pingApps = pingHelper.Install(nodes.Get(0));
202 pingApps.Start(MilliSeconds(10));
203 pingApps.Stop(MilliSeconds(500));
205 Ptr<TrafficGenerator> trafficGenerator =
207 Ptr<PacketSink> packetSink = sinkApplication.Get(0)->GetObject<PacketSink>();
209 uint64_t previousBytesSent = 0;
210 uint64_t previousBytesReceived = 0;
211 uint64_t previousWindowBytesSent = 0;
213 std::ofstream outFileTx;
214 std::string txFileName =
"tx-" + GetName(trafficType) +
".csv";
215 outFileTx.open(txFileName.c_str(), std::ios_base::out);
217 NS_ABORT_MSG_IF(!outFileTx.is_open(),
"Can't open file " << txFileName);
218 outFileTx.setf(std::ios_base::fixed);
220 for (uint32_t i = appStartMs; i < appStartMs + appDurationMs; i = i + measWindowMs)
222 Simulator::Schedule(MilliSeconds(i),
226 &previousWindowBytesSent,
229 Simulator::Schedule(MilliSeconds(i),
232 &previousBytesReceived);
235 Simulator::Stop(MilliSeconds(appStartMs + appDurationMs));
237 Simulator::Destroy();
240 std::cout <<
"\n Traffic generator example finished. Results written into " << txFileName
241 <<
" file in the ns-3-dev root directory." << std::endl;
A helper to make it easier to instantiate an ns3::TrafficGenerator types of applications on a set of ...
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.