|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include "ns3/core-module.h"
23 #include "ns3/network-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/point-to-point-module.h"
26 #include "ns3/applications-module.h"
27 #include "ns3/traffic-control-module.h"
28 #include "ns3/flow-monitor-module.h"
72 std::cout <<
"TcPacketsInQueue " << oldValue <<
" to " << newValue << std::endl;
78 std::cout <<
"DevicePacketsInQueue " << oldValue <<
" to " << newValue << std::endl;
84 std::cout <<
"Sojourn time " << sojournTime.
ToDouble (
Time::MS) <<
"ms" << std::endl;
88 main (
int argc,
char *argv[])
90 double simulationTime = 10;
91 std::string transportProt =
"Tcp";
92 std::string socketType;
95 cmd.AddValue (
"transportProt",
"Transport protocol to use: Tcp, Udp", transportProt);
96 cmd.Parse (argc, argv);
98 if (transportProt.compare (
"Tcp") == 0)
100 socketType =
"ns3::TcpSocketFactory";
104 socketType =
"ns3::UdpSocketFactory";
136 address.SetBase (
"10.1.1.0",
"255.255.255.0");
149 uint32_t payloadSize = 1448;
153 onoff.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
154 onoff.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
155 onoff.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
156 onoff.SetAttribute (
"DataRate",
StringValue (
"50Mbps"));
162 onoff.SetAttribute (
"Remote", remoteAddress);
163 apps.
Add (onoff.Install (
nodes.Get (1)));
174 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->
GetFlowStats ();
175 std::cout << std::endl <<
"*** Flow monitor statistics ***" << std::endl;
176 std::cout <<
" Tx Packets/Bytes: " << stats[1].txPackets
177 <<
" / " << stats[1].txBytes << std::endl;
178 std::cout <<
" Offered Load: " << stats[1].txBytes * 8.0 / (stats[1].timeLastTxPacket.GetSeconds () - stats[1].timeFirstTxPacket.GetSeconds ()) / 1000000 <<
" Mbps" << std::endl;
179 std::cout <<
" Rx Packets/Bytes: " << stats[1].rxPackets
180 <<
" / " << stats[1].rxBytes << std::endl;
181 uint32_t packetsDroppedByQueueDisc = 0;
182 uint64_t bytesDroppedByQueueDisc = 0;
188 std::cout <<
" Packets/Bytes Dropped by Queue Disc: " << packetsDroppedByQueueDisc
189 <<
" / " << bytesDroppedByQueueDisc << std::endl;
190 uint32_t packetsDroppedByNetDevice = 0;
191 uint64_t bytesDroppedByNetDevice = 0;
197 std::cout <<
" Packets/Bytes Dropped by NetDevice: " << packetsDroppedByNetDevice
198 <<
" / " << bytesDroppedByNetDevice << std::endl;
199 std::cout <<
" Throughput: " << stats[1].rxBytes * 8.0 / (stats[1].timeLastRxPacket.GetSeconds () - stats[1].timeFirstRxPacket.GetSeconds ()) / 1000000 <<
" Mbps" << std::endl;
200 std::cout <<
" Mean delay: " << stats[1].delaySum.GetSeconds () / stats[1].rxPackets << std::endl;
201 std::cout <<
" Mean jitter: " << stats[1].jitterSum.GetSeconds () / (stats[1].rxPackets - 1) << std::endl;
203 for (
auto p : dscpVec)
205 std::cout <<
" DSCP value: 0x" << std::hex << static_cast<uint32_t> (p.first) << std::dec
206 <<
" count: "<< p.second << std::endl;
211 std::cout << std::endl <<
"*** Application statistics ***" << std::endl;
213 uint64_t totalPacketsThr = DynamicCast<PacketSink> (sinkApp.
Get (0))->GetTotalRx ();
214 thr = totalPacketsThr * 8 / (simulationTime * 1000000.0);
215 std::cout <<
" Rx Bytes: " << totalPacketsThr << std::endl;
216 std::cout <<
" Average Goodput: " << thr <<
" Mbit/s" << std::endl;
217 std::cout << std::endl <<
"*** TC Layer statistics ***" << std::endl;
218 std::cout << q->
GetStats () << std::endl;
holds a vector of ns3::NetDevice pointers
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
Parse command-line arguments.
void TcPacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
uint16_t SetRootQueueDisc(const std::string &type, Args &&... args)
Helper function used to set a root queue disc of the given type and with the given attributes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
AttributeValue implementation for Address.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
double ToDouble(enum Unit unit) const
Get the Time value expressed in a particular unit.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Helper to enable IP flow monitoring on a set of Nodes.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
QueueDiscContainer Install(NetDeviceContainer c)
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
a polymophic address class
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Holds a vector of ns3::QueueDisc pointers.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void DevicePacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
Simulation virtual time values and global simulation resolution.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static void Run(void)
Run the simulation.
Hold variables of type string.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
std::vector< std::pair< Ipv4Header::DscpType, uint32_t > > GetDscpCounts(FlowId flowId) const
get the DSCP values of the packets belonging to the flow with the given FlowId, sorted in decreasing ...
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
@ DROP_QUEUE_DISC
Packet dropped by the queue disc.
static Ipv4Address GetAny(void)
@ DROP_QUEUE
Packet dropped due to queue overflow.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Time Seconds(double value)
Construct a Time in the indicated unit.
Build a set of QueueDisc objects.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
Build a set of PointToPointNetDevice objects.
keep track of a set of node pointers.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
const Stats & GetStats(void)
Retrieve all the collected statistics.
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
aggregate IP/TCP/UDP functionality to existing Nodes.
void SojournTimeTrace(Time sojournTime)
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.