21#include "ns3/applications-module.h"
22#include "ns3/core-module.h"
23#include "ns3/flow-monitor-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/network-module.h"
26#include "ns3/point-to-point-module.h"
27#include "ns3/traffic-control-module.h"
77 std::cout <<
"TcPacketsInQueue " << oldValue <<
" to " << newValue << std::endl;
89 std::cout <<
"DevicePacketsInQueue " << oldValue <<
" to " << newValue << std::endl;
100 std::cout <<
"Sojourn time " << sojournTime.
ToDouble(Time::MS) <<
"ms" << std::endl;
104main(
int argc,
char* argv[])
106 double simulationTime = 10;
107 std::string transportProt =
"Tcp";
108 std::string socketType;
111 cmd.AddValue(
"transportProt",
"Transport protocol to use: Tcp, Udp", transportProt);
112 cmd.Parse(argc, argv);
114 if (transportProt ==
"Tcp")
116 socketType =
"ns3::TcpSocketFactory";
120 socketType =
"ns3::UdpSocketFactory";
144 "/NodeList/1/$ns3::TrafficControlLayer/RootQueueDiscList/0/SojournTime",
153 address.SetBase(
"10.1.1.0",
"255.255.255.0");
169 OnOffHelper onoff(socketType, Ipv4Address::GetAny());
170 onoff.SetAttribute(
"OnTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=1]"));
171 onoff.SetAttribute(
"OffTime",
StringValue(
"ns3::ConstantRandomVariable[Constant=0]"));
172 onoff.SetAttribute(
"PacketSize",
UintegerValue(payloadSize));
173 onoff.SetAttribute(
"DataRate",
StringValue(
"50Mbps"));
179 onoff.SetAttribute(
"Remote", remoteAddress);
187 Simulator::Stop(
Seconds(simulationTime + 5));
191 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
192 std::cout << std::endl <<
"*** Flow monitor statistics ***" << std::endl;
193 std::cout <<
" Tx Packets/Bytes: " << stats[1].txPackets <<
" / " << stats[1].txBytes
195 std::cout <<
" Offered Load: "
196 << stats[1].txBytes * 8.0 /
197 (stats[1].timeLastTxPacket.GetSeconds() -
198 stats[1].timeFirstTxPacket.GetSeconds()) /
200 <<
" Mbps" << std::endl;
201 std::cout <<
" Rx Packets/Bytes: " << stats[1].rxPackets <<
" / " << stats[1].rxBytes
203 uint32_t packetsDroppedByQueueDisc = 0;
204 uint64_t bytesDroppedByQueueDisc = 0;
205 if (stats[1].packetsDropped.size() > Ipv4FlowProbe::DROP_QUEUE_DISC)
207 packetsDroppedByQueueDisc = stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE_DISC];
208 bytesDroppedByQueueDisc = stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE_DISC];
210 std::cout <<
" Packets/Bytes Dropped by Queue Disc: " << packetsDroppedByQueueDisc <<
" / "
211 << bytesDroppedByQueueDisc << std::endl;
212 uint32_t packetsDroppedByNetDevice = 0;
213 uint64_t bytesDroppedByNetDevice = 0;
214 if (stats[1].packetsDropped.size() > Ipv4FlowProbe::DROP_QUEUE)
216 packetsDroppedByNetDevice = stats[1].packetsDropped[Ipv4FlowProbe::DROP_QUEUE];
217 bytesDroppedByNetDevice = stats[1].bytesDropped[Ipv4FlowProbe::DROP_QUEUE];
219 std::cout <<
" Packets/Bytes Dropped by NetDevice: " << packetsDroppedByNetDevice <<
" / "
220 << bytesDroppedByNetDevice << std::endl;
221 std::cout <<
" Throughput: "
222 << stats[1].rxBytes * 8.0 /
223 (stats[1].timeLastRxPacket.GetSeconds() -
224 stats[1].timeFirstRxPacket.GetSeconds()) /
226 <<
" Mbps" << std::endl;
227 std::cout <<
" Mean delay: " << stats[1].delaySum.GetSeconds() / stats[1].rxPackets
229 std::cout <<
" Mean jitter: " << stats[1].jitterSum.GetSeconds() / (stats[1].rxPackets - 1)
231 auto dscpVec = classifier->GetDscpCounts(1);
232 for (
auto p : dscpVec)
234 std::cout <<
" DSCP value: 0x" << std::hex << static_cast<uint32_t>(p.first) << std::dec
235 <<
" count: " << p.second << std::endl;
238 Simulator::Destroy();
240 std::cout << std::endl <<
"*** Application statistics ***" << std::endl;
242 uint64_t totalPacketsThr = DynamicCast<PacketSink>(sinkApp.
Get(0))->GetTotalRx();
243 thr = totalPacketsThr * 8 / (simulationTime * 1000000.0);
244 std::cout <<
" Rx Bytes: " << totalPacketsThr << std::endl;
245 std::cout <<
" Average Goodput: " << thr <<
" Mbit/s" << std::endl;
246 std::cout << std::endl <<
"*** TC Layer statistics ***" << std::endl;
247 std::cout << q->
GetStats() << std::endl;
a polymophic address class
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
Helper to enable IP flow monitoring on a set of Nodes.
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
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.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
Holds a vector of ns3::QueueDisc pointers.
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
const Stats & GetStats()
Retrieve all the collected statistics.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double ToDouble(Unit unit) const
Get the Time value expressed in a particular unit.
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
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.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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 TcPacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
Number of packets in TX queue trace.
void SojournTimeTrace(Time sojournTime)
TC Soujoun time trace.
void DevicePacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
Packets in the device queue trace.