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;
82 main (
int argc,
char *argv[])
84 double simulationTime = 10;
85 std::string transportProt =
"Tcp";
86 std::string socketType;
89 cmd.
AddValue (
"transportProt",
"Transport protocol to use: Tcp, Udp", transportProt);
90 cmd.
Parse (argc, argv);
92 if (transportProt.compare (
"Tcp") == 0)
94 socketType =
"ns3::TcpSocketFactory";
98 socketType =
"ns3::UdpSocketFactory";
110 devices = pointToPoint.
Install (nodes);
133 address.
SetBase (
"10.1.1.0",
"255.255.255.0");
146 uint32_t payloadSize = 1448;
150 onoff.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
151 onoff.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
152 onoff.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
153 onoff.SetAttribute (
"DataRate",
StringValue (
"50Mbps"));
157 onoff.SetAttribute (
"Remote", remoteAddress);
158 apps.
Add (onoff.Install (nodes.
Get (1)));
169 std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->
GetFlowStats ();
170 std::cout << std::endl <<
"*** Flow monitor statistics ***" << std::endl;
171 std::cout <<
" Tx Packets: " << stats[1].txPackets << std::endl;
172 std::cout <<
" Tx Bytes: " << stats[1].txBytes << std::endl;
173 std::cout <<
" Offered Load: " << stats[1].txBytes * 8.0 / (stats[1].timeLastTxPacket.GetSeconds () - stats[1].timeFirstTxPacket.GetSeconds ()) / 1000000 <<
" Mbps" << std::endl;
174 std::cout <<
" Rx Packets: " << stats[1].rxPackets << std::endl;
175 std::cout <<
" Rx Bytes: " << stats[1].rxBytes << std::endl;
180 std::cout <<
" Throughput: " << stats[1].rxBytes * 8.0 / (stats[1].timeLastRxPacket.GetSeconds () - stats[1].timeFirstRxPacket.GetSeconds ()) / 1000000 <<
" Mbps" << std::endl;
181 std::cout <<
" Mean delay: " << stats[1].delaySum.GetSeconds () / stats[1].rxPackets << std::endl;
182 std::cout <<
" Mean jitter: " << stats[1].jitterSum.GetSeconds () / (stats[1].rxPackets - 1) << std::endl;
186 std::cout << std::endl <<
"*** Application statistics ***" << std::endl;
188 uint32_t totalPacketsThr = DynamicCast<PacketSink> (sinkApp.
Get (0))->GetTotalRx ();
189 thr = totalPacketsThr * 8 / (simulationTime * 1000000.0);
190 std::cout <<
" Rx Bytes: " << totalPacketsThr << std::endl;
191 std::cout <<
" Average Goodput: " << thr <<
" Mbit/s" << std::endl;
192 std::cout << std::endl <<
"*** TC Layer statistics ***" << std::endl;
195 std::cout <<
" Packets dropped by the netdevice: " << queue->GetTotalDroppedPackets () << std::endl;
holds a vector of ns3::Application pointers.
const FlowStatsContainer & GetFlowStats() const
Retrieve all collected the flow statistics.
static Ipv4Address GetAny(void)
Ptr< Queue > GetQueue(void) const
Get a copy of the attached Queue.
QueueDiscContainer Install(NetDeviceContainer c)
holds a vector of std::pair of Ptr and interface index.
Hold variables of type string.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
uint32_t GetTotalRequeuedPackets(void) const
Get the total number of requeued packets.
void SetQueue(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue())
Each point to point net device must have a queue to pass packets through.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
Holds a vector of ns3::QueueDisc pointers.
Ptr< QueueDisc > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Packet dropped due to queue overflow.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Build a set of QueueDisc objects.
Ptr< FlowMonitor > InstallAll()
Enable flow monitoring on all nodes.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Ptr< FlowClassifier > GetClassifier()
Retrieve the FlowClassifier object for IPv4 created by the Install* methods.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr
stored in this container at a given index.
uint32_t GetTotalDroppedPackets(void) const
Get the total number of dropped packets.
uint16_t SetRootQueueDisc(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to set a root queue disc of the given type and with the given attributes...
void TcPacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
uint32_t GetTotalDroppedBytes(void) const
Get the total amount of dropped bytes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Helper to enable IP flow monitoring on a set of Nodes.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add the given number of internal queues (of the given type and with the given...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &value)
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Packet dropped by the queue disc.
void DevicePacketsInQueueTrace(uint32_t oldValue, uint32_t newValue)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const