#include "ns3/log.h"
#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/dce-module.h"
#include "ns3/flow-monitor-module.h"
#include "ns3/traffic-control-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ECN-TEST");
std::string m_stack = "dce";
std::string sock_factory = "ns3::LinuxTcpSocketFactory";
int m_seed = 1;
double startTime = 4.0;
double stopTime = 20.0;
int m_nNodes = 1;
bool enablePcap = true;
std::string m_pktSize = "1024";
bool m_frag = false;
bool m_bulk = false;
static void RunIp (Ptr<Node> node, Time at, std::string str)
{
DceApplicationHelper process;
ApplicationContainer apps;
process.SetBinary ("ip");
process.SetStackSize (1 << 16);
process.ResetArguments ();
process.ParseArguments (str.c_str ());
apps = process.Install (node);
apps.Start (at);
}
int
main (int argc, char *argv[])
{
// LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
// LogComponentEnable ("PacketSink", LOG_LEVEL_INFO);
/*CommandLine cmd;
cmd.AddValue ("stack", "choose network stack", m_stack);
cmd.AddValue ("seed", "randomize seed", m_seed);
cmd.AddValue ("nNodes", "the number of nodes in left side", m_nNodes);
cmd.AddValue ("stopTime", "duration", stopTime);
cmd.AddValue ("enablePcap", "pcap", enablePcap);
cmd.AddValue ("pktSize", "packet size", m_pktSize);
cmd.AddValue ("frag", "fragment", m_frag);
cmd.AddValue ("bulk", "use BulkSendApp instead of OnOffApp", m_bulk);
cmd.Parse (argc, argv);*/
SeedManager::SetSeed (m_seed);
NodeContainer lefts, routers, rights, nodes;
lefts.Create (m_nNodes);
routers.Create (1);
rights.Create (m_nNodes);
nodes = NodeContainer (lefts, routers, rights);
DceManagerHelper dceManager;
LinuxStackHelper stack;
InternetStackHelper stack_net;
GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
// internetStack.Install (routers);
sock_factory = "ns3::LinuxTcpSocketFactory";
//sock_factory = "ns3::TcpSocketFactory";
dceManager.SetNetworkStack ("ns3::LinuxSocketFdFactory",
"Library", StringValue ("liblinux.so"));
stack_net.Install (routers);
stack.Install (lefts);
stack.Install (rights);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ns"));
Config::SetDefault ("ns3::RedQueueDisc::UseEcn", BooleanValue (true));
TrafficControlHelper tchBottleneck;
QueueDiscContainer queueDiscs;
tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc");
Ipv4AddressHelper address;
Ipv4InterfaceContainer interfaces;
NetDeviceContainer dev0, dev1, dev2;
for (uint32_t i = 0; i < m_nNodes; i++)
{
std::ostringstream oss;
oss << "10.0." << i << ".0";
address.SetBase (oss.str ().c_str (), "255.255.255.0");
dev0 = pointToPoint.Install (NodeContainer (lefts.Get (i), routers.Get (0)));
queueDiscs = tchBottleneck.Install (dev0.Get (1));
address.Assign (dev0);
}
// bottle neck link
/*pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("2Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("100ms"));
dev1 = pointToPoint.Install (NodeContainer (routers.Get (0), routers.Get (1)));
if (m_frag)
{
dev1.Get (0)->SetMtu (1000);
dev1.Get (1)->SetMtu (1000);
}*/
// bottle neck link
/*Ptr<RateErrorModel> em1 =
CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
"ErrorRate", DoubleValue (0.5),
"ErrorUnit", EnumValue (RateErrorModel::ERROR_UNIT_PACKET)
);
dev0.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em1));*/
/*address.SetBase ("10.1.0.0", "255.255.255.0");
address.Assign (dev1);*/
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("10ns"));
TrafficControlHelper tchBottleneck2;
QueueDiscContainer queueDiscs2;
tchBottleneck2.SetRootQueueDisc ("ns3::RedQueueDisc");
// for right links
for (uint32_t i = 0; i < m_nNodes; i++)
{
std::ostringstream oss;
oss << "10.2." << i << ".0";
address.SetBase (oss.str ().c_str (), "255.255.255.0");
dev2 = pointToPoint.Install (NodeContainer (routers.Get (0), rights.Get (i)));
queueDiscs = tchBottleneck2.Install (dev2.Get (0));
address.Assign (dev2);
}
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
LinuxStackHelper::PopulateRoutingTables ();
dceManager.Install (nodes);
//stack.SysctlSet (nodes, ".net.ipv4.conf.default.forwarding", "1");
//------------------------------------------------------------------------------------------
//stack.SysctlSet (nodes, ".net.ipv4.tcp_ecn", "1");
//stack.SysctlSet (routers, ".net.core.default_qdisc", "sch_red");
//------------------------------------------
//router setting
/*DceApplicationHelper process_router;
ApplicationContainer router_app;
process_router.SetBinary ("tc");
process_router.SetStackSize (1 << 16);
process_router.ResetArguments ();
RunIp (routers.Get (0), Seconds (0.2), "link show");
process_router.ParseArguments ("qdisc add dev eth0 root handle 1: red limit 3000 min 1200 avpkt 1024 burst 2 bandwidth 10mbit probability 0.4 ecn");
router_app = process_router.Install (routers);
router_app.Start (Seconds (1.0));*/
//RunIp (routers.Get(0), Seconds (1), "link show");
/*DceApplicationHelper process;
process.SetBinary ("echo");
process.AddArgument ("hello-dce");
process.SetStackSize (1 << 16);
ApplicationContainer apps1 = process.Install (routers);
apps1.Start (Seconds (1.0));*/
//-------------------------------------------
ApplicationContainer apps;
DceApplicationHelper process;
BulkSendHelper bulk = BulkSendHelper (sock_factory,
InetSocketAddress ("10.2.0.2", 2000));
// Set the amount of data to send in bytes. Zero is unlimited.
bulk.SetAttribute ("MaxBytes", UintegerValue (0));
bulk.SetAttribute ("SendSize", UintegerValue (atoi (m_pktSize.c_str ())));
// Flow 1 - n
for (uint32_t i = 0; i < m_nNodes; i++)
{
std::ostringstream oss;
oss << "10.2." << i << ".2";
bulk.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
apps = bulk.Install (lefts.Get (i));
apps.Start (Seconds (startTime));
}
PacketSinkHelper sink = PacketSinkHelper (sock_factory,
InetSocketAddress (Ipv4Address::GetAny (), 2000));
apps = sink.Install (rights);
apps.Start (Seconds (2));
if (enablePcap)
{
pointToPoint.EnablePcapAll ("ecn-test");
}
//stack.SysctlSet (routers, ".net.ipv4.ip_forward", "1812");
//stack.SysctlSet (routers, ".net.core.default_qdisc", "sch_red");
stack.SysctlSet (nodes, ".net.mptcp.mptcp_enabled", "0");
stack.SysctlSet (nodes, ".net.ipv4.tcp_congestion_control", "dctcp");
Simulator::Stop (Seconds (stopTime));
Simulator::Run ();
Ptr<PacketSink> pktsink;
uint64_t total = 0;
std::cout << "Total ";
for (uint32_t i = 0; i < m_nNodes; i++)
{
pktsink = apps.Get (i)->GetObject<PacketSink> ();
std::cout << "Rx(" << i << ") = " << pktsink->GetTotalRx ()
<< " bytes ("
<< pktsink->GetTotalRx () * 8 / (stopTime - startTime)
<< " bps), ";
total += pktsink->GetTotalRx () ;
}
std::cout << " total = " << total * 8 / (stopTime - startTime) << " bps";
std::cout << std::endl;
Simulator::Destroy ();
return 0;
}