36#include "ns3/applications-module.h"
37#include "ns3/core-module.h"
38#include "ns3/internet-module.h"
39#include "ns3/mobility-module.h"
40#include "ns3/network-module.h"
41#include "ns3/wifi-module.h"
68main(
int argc,
char* argv[])
71 std::string socketType{
"ipv4"};
75 cmd.Usage(
"Basic VoIP example");
76 cmd.AddValue(
"duration",
"Duration of traffic flow, in seconds", duration);
77 cmd.AddValue(
"socketType",
78 "Socket type to use (ipv4, ipv6, or packet). Default: ipv4",
80 cmd.AddValue(
"verbose",
81 "Enable verbose logging of TgaxVoipTraffic, PacketSink, and this program",
83 cmd.Parse(argc, argv);
118 wifiDevices.
Add(apDevices);
121 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(ssid));
123 wifiDevices.
Add(staDevices);
126 mobility.SetPositionAllocator(
"ns3::GridPositionAllocator",
139 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
150 if (socketType ==
"ipv4")
153 ipv4.SetBase(
"10.1.1.0",
"255.255.255.0");
154 ipv4Interfaces =
ipv4.Assign(wifiDevices);
158 else if (socketType ==
"ipv6")
162 ipv6Interfaces = ipv6.
Assign(wifiDevices);
167 std::string protocol;
169 uint16_t remotePort = 5000;
171 if (socketType ==
"ipv4")
173 protocol =
"ns3::UdpSocketFactory";
176 else if (socketType ==
"ipv6")
178 protocol =
"ns3::UdpSocketFactory";
181 else if (socketType ==
"packet")
183 protocol =
"ns3::PacketSocketFactory";
205 if (socketType ==
"ipv4")
208 activePayloadSize += 3;
211 else if (socketType ==
"ipv6")
214 activePayloadSize += 5;
218 sourceHelper.SetAttribute(
"Protocol",
StringValue(protocol));
219 sourceHelper.SetAttribute(
"ActivePacketPayloadSize",
UintegerValue(activePayloadSize));
220 sourceHelper.SetAttribute(
"SilencePacketPayloadSize",
UintegerValue(silencePayloadSize));
231 if (socketType ==
"ipv4")
235 else if (socketType ==
"ipv6")
245 remoteAddr = socketAddr;
248 sourceHelper.SetAttribute(
"Remote",
AddressValue(remoteAddr));
251 auto sourceApps = sourceHelper.Install(staNode);
252 sourceApps.Start(
Seconds(1.0));
253 sourceApps.Stop(
Seconds(1.0) + duration);
256 if (socketType ==
"ipv4")
260 else if (socketType ==
"ipv6")
270 sinkAddr = socketAddr;
274 auto sinkApps = sinkHelper.Install(apNode);
276 sinkApps.Stop(
Seconds(2.0) + duration);
278 NS_LOG_INFO(
"PacketSink application installed on AP (Node 0)");
282 "/NodeList/*/ApplicationList/*/$ns3::TgaxVoipTraffic/TxWithJitter",
295 NS_LOG_INFO(
"Active payload size: " << activePayloadSize <<
" bytes");
296 NS_LOG_INFO(
"Silence payload size: " << silencePayloadSize <<
" bytes");
306 NS_LOG_INFO(
"Total bytes received: " << totalBytes);
330 NS_LOG_INFO(
"VoIP TX: " <<
" Packet size (bytes): " << packet->GetSize()
339 :
"INACTIVE_SILENCE";
346 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()
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class to auto-assign global IPv6 unicast addresses.
void SetBase(Ipv6Address network, Ipv6Prefix prefix, Ipv6Address base=Ipv6Address("::1"))
Set the base network number, network prefix, and base interface ID.
Ipv6InterfaceContainer Assign(const NetDeviceContainer &c)
Allocate an Ipv6InterfaceContainer with auto-assigned addresses.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Keep track of a set of IPv6 interfaces.
Describes an IPv6 prefix.
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.
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.
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
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.
VoiceActivityState
Voice activity states.
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.
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.
const uint32_t silencePayloadSize
payload size of silence packets in bytes
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 PacketReceived(std::string context, Ptr< const Packet > packet, const Address &address)
Callback invoked when the PacketSink receives a packet.
void VoipPacketSent(Ptr< const Packet > packet, Time jitter)
Callback invoked when a VoIP packet is transmitted.
void VoipStateChanged(TgaxVoipTraffic::VoiceActivityState state, Time duration)
Callback invoked when the VoIP application state changes (active/silence).
Ptr< PacketSink > sink
Pointer to the packet sink application.