Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
187d091
Added Traffic Control Layer
natale-p Oct 7, 2015
eb9a024
Internet depends on traffic-control
natale-p Oct 7, 2015
262931f
Made public ProtocolHandlerEntry struct in node.h
natale-p Oct 7, 2015
80baa0f
Aggregate TrafficControlLayer on any Internet-enabled node
natale-p Oct 7, 2015
9285b11
Aggregate TCLayer by default on tests
natale-p Oct 7, 2015
cbafa49
Register callbacks on TCLayer and NetDevices, RX side
natale-p Oct 7, 2015
11f20e7
Use traffic-control to send packets
natale-p Oct 7, 2015
0c814e4
Initial support for multiple transmission queues inside NetDevices
stavallo Nov 19, 2015
ef2c685
WifiNetDevices can return the number of transmission queues based on …
stavallo Nov 19, 2015
bb27480
Flow control Part I: NetDeviceQueues can be started, stopped and woken
stavallo Oct 20, 2015
610f9c7
PointToPointNetDevice: Add support for flow control
stavallo Nov 12, 2015
251787d
NetDevices return the index of the transmission queue they select for…
stavallo Nov 20, 2015
bd130e8
Make Queue store QueueItem objects
stavallo Jan 5, 2016
2bf15fb
Add the QueueDisc base class
stavallo Oct 23, 2015
6e6ba99
The traffic control layer enqueues packets in the queue disc
stavallo Dec 4, 2015
4dd14d5
Defer the addition of the IP header until the packet is extracted fro…
stavallo Jan 6, 2016
9881fe5
Ipv4Header: Add GetVersion and make DscpTypeToString static
stavallo Jan 8, 2016
106f8f2
Add the pfifo_fast queue disc
stavallo Jan 9, 2016
7d99326
Add a queue disc helper to ease the installation of queue discs
stavallo Dec 2, 2015
d850946
Add a traffic control example
pasquimp Nov 25, 2015
0815e6b
Add a pfifo_fast test suite
pasquimp Dec 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a traffic control example
Signed-off-by: Stefano Avallone <[email protected]>
  • Loading branch information
pasquimp authored and stavallo committed Jan 15, 2016
commit d850946b51d0310d117096690950443920348005
117 changes: 117 additions & 0 deletions examples/traffic-control/traffic-control.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015 Universita' degli Studi di Napoli "Federico II"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Pasquale Imputato <[email protected]>
* Author: Stefano Avallone <[email protected]>
*/

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/traffic-control-module.h"

// This simple example shows how to use TrafficContorlHelper to install a QueueDisc on a device.
// The default QueueDisc is a pfifo_fast with max number of packets equal to 1000 (as in Linux)
//
// Network topology
//
// 10.1.1.0
// n0 -------------- n1
// point-to-point

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("TrafficControlExample");

void
PacketsInQueueTrace (uint32_t oldValue, uint32_t newValue)
{
std::cout << "PacketsInQueue " << oldValue << " to " << newValue << std::endl;
}

int
main (int argc, char *argv[])
{
double simulationTime = 10; //seconds

NodeContainer nodes;
nodes.Create (2);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
pointToPoint.SetQueue ("ns3::DropTailQueue", "Mode", StringValue ("QUEUE_MODE_PACKETS"), "MaxPackets", UintegerValue (1000));

NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);

InternetStackHelper stack;
stack.Install (nodes);

QueueDiscHelper qdh;
qdh.SetQueueDiscType ("ns3::PfifoFastQueueDisc");
qdh.SetAttribute ("Band0", PointerValue (CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (1000))));
qdh.SetAttribute ("Band1", PointerValue (CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (1000))));
qdh.SetAttribute ("Band2", PointerValue (CreateObjectWithAttributes<DropTailQueue> ("MaxPackets", UintegerValue (1000))));
QueueDiscContainer qdiscs = qdh.Install (devices);

Ptr<QueueDisc> q = qdiscs.Get (0);
q->TraceConnectWithoutContext ("PacketsInQueue", MakeCallback (&PacketsInQueueTrace));

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");

Ipv4InterfaceContainer interfaces = address.Assign (devices);

//Flow
uint16_t port = 7;
Address localAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", localAddress);
ApplicationContainer sinkApp = packetSinkHelper.Install (nodes.Get (0));

sinkApp.Start (Seconds (0.0));
sinkApp.Stop (Seconds (simulationTime + 0.1));

uint32_t payloadSize = 1448;
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (payloadSize));

OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ());
onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
onoff.SetAttribute ("PacketSize", UintegerValue (payloadSize));
onoff.SetAttribute ("DataRate", DataRateValue (1000000000)); //bit/s
ApplicationContainer apps;

AddressValue remoteAddress (InetSocketAddress (interfaces.GetAddress (0), port));
onoff.SetAttribute ("Remote", remoteAddress);
apps.Add (onoff.Install (nodes.Get (1)));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (simulationTime + 0.1));

Simulator::Stop (Seconds (simulationTime + 0.1));
Simulator::Run ();
Simulator::Destroy ();

double thr = 0;
uint32_t totalPacketsThr = DynamicCast<PacketSink> (sinkApp.Get (0))->GetTotalRx ();
thr = totalPacketsThr * 8 / (simulationTime * 1000000.0); //Mbit/s
std::cout << thr << " Mbit/s" <<std::endl;

return 0;
}
6 changes: 6 additions & 0 deletions examples/traffic-control/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

def build(bld):
obj = bld.create_ns3_program('traffic-control',
['internet', 'point-to-point', 'applications', 'traffic-control'])
obj.source = 'traffic-control.cc'