41#include "ns3/applications-module.h"
42#include "ns3/core-module.h"
43#include "ns3/internet-module.h"
44#include "ns3/mobility-module.h"
45#include "ns3/network-module.h"
46#include "ns3/wifi-module.h"
74main(
int argc,
char* argv[])
77 std::string model{
"BV1"};
78 std::string protocol{
"udp"};
82 cmd.Usage(
"Buffered video streaming example");
83 cmd.AddValue(
"duration",
"Duration of traffic flow, in seconds", duration);
85 "Traffic model to use (BV1, BV2, BV3, BV4, BV5, BV6, MC1, MC2, or Custom). "
88 cmd.AddValue(
"protocol",
"Protocol to use (udp or tcp). Default: udp", protocol);
89 cmd.AddValue(
"verbose",
90 "Enable verbose logging of TgaxVideoTraffic, PacketSink, and this program",
92 cmd.Parse(argc, argv);
108 bool isMulticast = (model ==
"MC1" || model ==
"MC2");
109 uint32_t numStations = isMulticast ? 2 : 1;
112 wifiNodes.
Create(1 + numStations);
116 for (
uint32_t i = 0; i < numStations; ++i)
118 staNodes.
Add(wifiNodes.
Get(1 + i));
138 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssid));
142 mobility.SetPositionAllocator(
"ns3::GridPositionAllocator",
155 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
162 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
165 allDevices.
Add(apDevices);
166 allDevices.
Add(staDevices);
170 for (
uint32_t i = 0; i < numStations; ++i)
175 std::string protocolFactory;
176 if (protocol ==
"udp")
178 protocolFactory =
"ns3::UdpSocketFactory";
180 else if (protocol ==
"tcp")
182 protocolFactory =
"ns3::TcpSocketFactory";
186 NS_FATAL_ERROR(
"Invalid protocol: " << protocol <<
". Use 'udp' or 'tcp'.");
189 uint16_t remotePort = 5000;
201 ipv4Proto->GetInterfaceForDevice(apNode->GetDevice(0)),
217 sourceHelper.SetAttribute(
"TrafficModelClassIdentifier",
StringValue(model));
220 sourceHelper.SetAttribute(
"Remote",
AddressValue(remoteAddr));
223 auto sourceApps = sourceHelper.Install(apNode);
224 sourceApps.Start(
Seconds(1.0));
225 sourceApps.Stop(
Seconds(1.0) + duration);
230 auto sinkApps = sinkHelper.Install(staNodes);
232 sinkApps.Stop(
Seconds(2.0) + duration);
234 NS_LOG_INFO(
"PacketSink application installed on STA node(s)");
238 "/NodeList/*/ApplicationList/*/$ns3::TgaxVideoTraffic/TxWithLatency",
243 "/NodeList/*/ApplicationList/*/$ns3::TgaxVideoTraffic/VideoFrameGenerated",
251 std::map<std::string, double> modelBitRates = {{
"BV1", 2.0},
261 double expectedBitRate = modelBitRates.count(model) ? modelBitRates[model] : 2.0;
266 NS_LOG_INFO(
"Expected bit rate: " << expectedBitRate <<
" Mbps");
269 NS_LOG_INFO(
"Multicast mode: delivering to " << numStations <<
" receivers");
276 uint64_t totalBytesReceived = 0;
277 for (
uint32_t i = 0; i < sinkApps.GetN(); ++i)
283 NS_LOG_INFO(
"STA " << i <<
" received: " << bytesRx <<
" bytes");
284 totalBytesReceived += bytesRx;
290 double expectedBytes = (expectedBitRate * 1e6 / 8) * duration.
GetSeconds();
291 NS_LOG_INFO(
"Total bytes received: " << totalBytesReceived);
292 NS_LOG_INFO(
"Approximate expected bytes per receiver: " << expectedBytes);
295 double measuredBitRate =
296 static_cast<double>(totalBytesReceived * 8) / (duration.
GetSeconds() * 1e6);
299 measuredBitRate /= numStations;
301 NS_LOG_INFO(
"Measured bit rate: " << measuredBitRate <<
" Mbps");
311 NS_LOG_INFO(
"Video TX: Packet size (bytes): " << packet->GetSize()
318 NS_LOG_INFO(
"Video Frame Generated: " << frameSize <<
" bytes");
324 NS_LOG_INFO(
"Packet RX: Size(bytes): " << packet->GetSize());
a polymophic address class
AttributeValue implementation for Address.
A helper to make it easier to instantiate an application on a set of nodes.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Access to the IPv4 forwarding table, interfaces, and configuration.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
static TypeId GetTypeId()
Get the type ID.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
AttributeValue implementation for TypeId.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Make it easy to create and manage PHY objects for the YANS model.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void Connect(std::string path, const CallbackBase &cb)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
LogLevel
Logging severity classes and levels.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
@ LOG_LEVEL_INFO
LOG_INFO and above.
void PacketReceived(std::string context, Ptr< const Packet > packet, const Address &address)
Callback invoked when the PacketSink receives a packet.
void VideoFrameGenerated(uint32_t frameSize)
Callback invoked when a video frame is generated.
void PacketReceived(std::string context, Ptr< const Packet > packet, const Address &address)
Callback invoked when the PacketSink receives a packet.
void VideoPacketSent(Ptr< const Packet > packet, Time latency)
Callback invoked when a video packet is transmitted.
Ptr< PacketSink > sink
Pointer to the packet sink application.