Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
- /*
- * Copyright (c) 2012 NICT
- *
- * 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: Hajime Tazaki <tazaki@nict.go.jp>
- */
- #include<iostream>
- #include<fstream>
- #include <vector>
- #include <sstream>
- #include <string>
- #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/flow-monitor-module.h"
- #include "ns3/config-store-module.h"
- #include "ns3/packet-sink.h"
- using namespace ns3;
- NS_LOG_COMPONENT_DEFINE ("DceNs3Dumbbell");
- std::string sock_factory = "ns3::TcpSocketFactory";
- int m_seed = 1;
- double error_p = 0;
- double startTime = 4.0;
- double stopTime = 34.0;
- int m_nNodes = 2;
- bool enablePcap = true;
- std::string pcapFile = "dce-ns3-comparison";
- uint32_t m_pktSize = 1500;
- bool m_frag = false;
- bool logging = false;
- bool pktDebug = true;
- std::vector<std::string> tcpVector;
- //std::string transProt = "ns3::TcpReno,ns3::TcpReno";
- std::string transProt = "TcpReno";
- uint32_t countDrops = 0;
- uint32_t countDropsDce = 0;
- uint32_t countTx = 0;
- uint32_t appcountDrops = 0;
- std::string accessLeftSpeed = "10Mbps";
- std::string accessRightSpeed = "10Mbps";
- std::string accessDelay = "0.1ms";
- std::string bottleneckSpeed = "2Mbps";
- std::string changingDelay = "0.1ms";
- std::string bottleneckDelay = "100ms";
- uint32_t queue_size = 65535;
- bool qMonitoring = false;
- std::string qSizeFileName = "routerQueueSize.txt";
- std::string cwnd_tr_file = "test";
- std::string ssthresh_tr_file = "test";
- std::string error_model_type = "rate";
- std::string instTput_file = "test";
- double old_time = 0.0;
- EventId output;
- Time current = Time::FromInteger(3, Time::S); //Only record cwnd and ssthresh values every 3 seconds
- bool first = true;
- std::string node_addr_file_name = "node_addresses.csv";
- uint16_t flowStepTime = 10;
- uint16_t pcapStartTime = 10;
- static void
- PcapScheduler (PointToPointHelper accessLeftLink, std::string pcapFile, NodeContainer lefts)
- {
- accessLeftLink.EnablePcap (pcapFile, lefts);
- }
- static void
- CwndTracer (Ptr<OutputStreamWrapper> stream, uint32_t oldval, uint32_t newval)
- {
- *stream->GetStream() << Simulator::Now().GetSeconds() << "," << oldval/1500 << "," << newval/1500 << std::endl;
- }
- static void
- TraceCwnd (std::string cwnd_tr_file_name)
- {
- AsciiTraceHelper ascii;
- Ptr<OutputStreamWrapper>stream = ascii.CreateFileStream(cwnd_tr_file_name.c_str());
- Config::ConnectWithoutContext ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",MakeBoundCallback (&CwndTracer, stream));
- }
- static void
- SendAppTx (Ptr<const Packet> p)
- {
- appcountDrops++;
- }
- static void
- RxDrop (Ptr<const Packet> p)
- {
- countDrops++;
- }
- static void
- SenderTx (Ptr<const Packet> p)
- {
- countTx++;
- }
- static void
- routerQSize(Ptr<Queue> queue, Ptr<OutputStreamWrapper> stream)
- {
- if (!Simulator::IsFinished())
- {
- *stream->GetStream() << Simulator::Now().GetSeconds() << "," << queue->GetNPackets() << std::endl;
- Simulator::Schedule (Seconds(0.001), &routerQSize, queue, stream);
- }
- }
- static void
- instTput(Ptr<PacketSink> pkt_sink, Ptr<OutputStreamWrapper> stream, double startTime, double stopTime)
- {
- if (!Simulator::IsFinished())
- {
- *stream->GetStream() << Simulator::Now().GetSeconds() << "," << (pkt_sink->GetTotalRx() * 8) / (Simulator::Now().GetSeconds() - startTime) << std::endl;
- Simulator::Schedule (Seconds(0.001), &instTput, pkt_sink, stream, startTime, stopTime);
- }
- }
- static void
- instTputCaller (std::string instTput_file_name, Ptr<PacketSink> pkt_sink, double startTime, double stopTime){
- AsciiTraceHelper ascii;
- Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream(instTput_file_name.c_str());
- instTput(pkt_sink, stream, startTime, stopTime);
- }
- static void
- SimStatus()
- {
- if (!Simulator::IsFinished())
- {
- std::cout << "The time elapsed is " << Simulator::Now().GetSeconds() << std::endl;
- Simulator::Schedule(Seconds(30), &SimStatus);
- }
- }
- int
- main (int argc, char *argv[])
- {
- if (logging){
- LogComponentEnable ("OnOffApplication", LOG_LEVEL_ALL);
- LogComponentEnable ("BulkSendApplication", LOG_LEVEL_ALL);
- LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
- LogComponentEnable ("Socket", LOG_LEVEL_ALL);
- LogComponentEnable ("TcpSocketBase", LOG_LEVEL_ALL);
- LogComponentEnable ("TcpL4Protocol", LOG_LEVEL_ALL);
- LogComponentEnable ("TcpSocket", LOG_LEVEL_ALL);
- }
- CommandLine cmd;
- cmd.AddValue("cwnd_tr_name", "Name of output trace file", cwnd_tr_file);
- cmd.AddValue("ssthresh_tr_name", "Name of output trace file", ssthresh_tr_file);
- 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 ("error", "Packet error rate", error_p);
- cmd.AddValue ("transProt", "Transport Protocol to use", transProt);
- cmd.AddValue ("pktDebug", "Packet Path Debugging", pktDebug);
- cmd.AddValue ("accessDelay", "Access Delay", accessDelay);
- cmd.AddValue ("changingDelay", "Access Changing Delay", changingDelay);
- cmd.AddValue ("bottleneckSpeed", "Bottleneck Speed", bottleneckSpeed);
- cmd.AddValue ("bottleneckDelay", "Bottleneck Delay", bottleneckDelay);
- cmd.AddValue ("queue_size", "Bottleneck Queue Size", queue_size);
- cmd.AddValue ("pcapFile", "pcap file name", pcapFile);
- cmd.AddValue ("qMonitoring", "Monitor queue", qMonitoring);
- cmd.AddValue ("qSizeFileName", "File name of queue size", qSizeFileName);
- cmd.AddValue ("error_model_type", "Error model type", error_model_type);
- cmd.AddValue ("accessLeftSpeed", "Access left speed", accessLeftSpeed);
- cmd.AddValue ("accessRightSpeed", "Access right speed", accessRightSpeed);
- cmd.AddValue ("flowStepTime", "Start of following flows", flowStepTime);
- cmd.AddValue ("pcapStartTime", "pcap measurement start time", pcapStartTime);
- cmd.AddValue ("instTput_file", "instantaneous throughput file name", instTput_file);
- cmd.Parse (argc, argv);
- SeedManager::SetSeed (m_seed);
- m_nNodes = 1;
- //NodeContainer lefts, routers, rights, nodes;
- NodeContainer lefts;
- lefts.Create (m_nNodes);
- NodeContainer routers;
- routers.Create (2);
- NodeContainer rights;
- rights.Create (m_nNodes);
- NodeContainer nodes;
- nodes = NodeContainer (lefts, routers, rights);
- InternetStackHelper internetStack;
- GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
- Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1448));
- internetStack.Install (nodes);
- std::stringstream leftNodeId, rightNodeId;
- for (int i =0; i<m_nNodes; i++)
- {
- leftNodeId << lefts.Get(i)->GetId ();
- rightNodeId << rights.Get(i)->GetId ();
- std::string specificLeftNode = "/NodeList/" + leftNodeId.str () + "/$ns3::TcpL4Protocol/SocketType";
- std::string specificRightNode = "/NodeList/" + rightNodeId.str () + "/$ns3::TcpL4Protocol/SocketType";
- std::cout << "specific left node is " << leftNodeId << std::endl;
- std::cout << "specific right node is " << rightNodeId << std::endl;
- if (transProt == "TcpTahoe")
- {
- Config::Set(specificLeftNode, TypeIdValue (TcpTahoe::GetTypeId()));
- Config::Set(specificRightNode, TypeIdValue (TcpTahoe::GetTypeId()));
- }
- else if (transProt == "TcpReno")
- {
- Config::Set(specificLeftNode, TypeIdValue (TcpReno::GetTypeId()));
- Config::Set(specificRightNode, TypeIdValue (TcpReno::GetTypeId()));
- }
- else if (transProt == "TcpNewReno")
- {
- Config::Set(specificLeftNode, TypeIdValue (TcpNewReno::GetTypeId()));
- Config::Set(specificRightNode, TypeIdValue (TcpNewReno::GetTypeId()));
- }
- else if (transProt == "TcpWestwood")
- {
- Config::Set(specificLeftNode, TypeIdValue (TcpWestwood::GetTypeId()));
- Config::Set(specificRightNode, TypeIdValue (TcpWestwood::GetTypeId()));
- Config::SetDefault("ns3::TcpWestwood::FilterType", EnumValue(TcpWestwood::TUSTIN));
- }
- else if (transProt == "TcpWestwoodPlus")
- {
- Config::Set(specificLeftNode, TypeIdValue (TcpWestwood::GetTypeId()));
- Config::Set(specificRightNode, TypeIdValue (TcpWestwood::GetTypeId()));
- Config::SetDefault("ns3::TcpWestwood::ProtocolType", EnumValue(TcpWestwood::WESTWOODPLUS));
- Config::SetDefault("ns3::TcpWestwood::FilterType", EnumValue(TcpWestwood::TUSTIN));
- }
- else
- {
- NS_LOG_DEBUG ("Invalid TCP version");
- exit (1);
- }
- }
- PointToPointHelper accessLeftLink;
- PointToPointHelper changingRTTLink;
- Ipv4AddressHelper address;
- RateErrorModel rate_error_model;
- Ptr<BurstErrorModel> burst_error_model = CreateObject<BurstErrorModel> ();
- if (error_model_type.compare("rate") == 0)
- {
- Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
- uv->SetStream (50);
- rate_error_model.SetRandomVariable(uv);
- rate_error_model.SetUnit(RateErrorModel::ERROR_UNIT_PACKET);
- rate_error_model.SetRate(error_p);
- }
- else if (error_model_type.compare("burst") == 0)
- {
- Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable>();
- uv->SetStream (50);
- burst_error_model->SetRandomVariable(uv);
- burst_error_model->SetAttribute("ErrorRate", DoubleValue (error_p));
- }
- else
- {
- NS_LOG_DEBUG ("Invalid error model");
- exit (1);
- }
- NetDeviceContainer dev0;
- for (int i = 0; i < m_nNodes; i++)
- {
- std::ostringstream oss;
- oss << "10.0." << i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- if (i==1){
- accessLeftLink.SetChannelAttribute ("Delay", StringValue (accessDelay));
- accessLeftLink.SetDeviceAttribute ("DataRate", StringValue (accessLeftSpeed));
- dev0 = accessLeftLink.Install (NodeContainer (lefts.Get (i), routers.Get (0)));
- }
- else{
- changingRTTLink.SetChannelAttribute ("Delay", StringValue (changingDelay));
- changingRTTLink.SetDeviceAttribute ("DataRate", StringValue (accessLeftSpeed));
- dev0 = changingRTTLink.Install (NodeContainer (lefts.Get (i), routers.Get (0)));
- }
- address.Assign (dev0);
- }
- PointToPointHelper bottleneckLink;
- bottleneckLink.SetDeviceAttribute ("DataRate", StringValue (bottleneckSpeed));
- bottleneckLink.SetChannelAttribute ("Delay", StringValue (bottleneckDelay));
- bottleneckLink.SetQueue ("ns3::DropTailQueue",
- "Mode", StringValue ("QUEUE_MODE_BYTES"),
- "MaxBytes", UintegerValue (queue_size));
- if (error_model_type.compare("rate") == 0)
- {
- bottleneckLink.SetDeviceAttribute ("ReceiveErrorModel", PointerValue (&rate_error_model));
- }
- else if (error_model_type.compare("burst") == 0)
- {
- bottleneckLink.SetDeviceAttribute ("ReceiveErrorModel", PointerValue (burst_error_model));
- }
- else
- {
- NS_LOG_DEBUG ("Invalid error model");
- exit (1);
- }
- NetDeviceContainer dev1;
- std::ostringstream oss;
- oss << "10.1.0.0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- dev1 = bottleneckLink.Install (NodeContainer (routers.Get (0), routers.Get (1)));
- address.Assign (dev1);
- PointToPointHelper accessRightLink;
- accessRightLink.SetDeviceAttribute ("DataRate", StringValue (accessRightSpeed));
- accessRightLink.SetChannelAttribute ("Delay", StringValue (accessDelay));
- NetDeviceContainer dev2;
- for (int i = 0; i < m_nNodes; i++)
- {
- std::ostringstream oss;
- oss << "10.2." << i << ".0";
- address.SetBase (oss.str ().c_str (), "255.255.255.0");
- if (i==1){
- accessRightLink.SetChannelAttribute ("Delay", StringValue (accessDelay));
- accessRightLink.SetDeviceAttribute ("DataRate", StringValue (accessRightSpeed));
- dev2 = accessRightLink.Install (NodeContainer (routers.Get (1), rights.Get (i)));
- }
- else{
- changingRTTLink.SetChannelAttribute ("Delay", StringValue (changingDelay));
- changingRTTLink.SetDeviceAttribute ("DataRate", StringValue (accessRightSpeed));
- dev2 = changingRTTLink.Install (NodeContainer (routers.Get (1), rights.Get (i)));
- }
- address.Assign (dev2);
- }
- Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- ApplicationContainer apps;
- BulkSendHelper ftp(sock_factory, InetSocketAddress (Ipv4Address ("10.2.0.2"), 2000));
- //BulkSendHelper ftp(sock_factory, Address());
- for(int i=0; i<m_nNodes; i++)
- {
- std::ostringstream oss;
- oss << "10.2." << i << ".2";
- ftp.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
- ftp.SetAttribute ("SendSize", UintegerValue (m_pktSize));
- ftp.SetAttribute ("MaxBytes", UintegerValue (0));
- apps = ftp.Install (lefts.Get(i));
- apps.Start (Seconds (startTime + flowStepTime*i));
- }
- Ptr<BulkSendApplication> senderNode = apps.Get(0)->GetObject<BulkSendApplication> ();
- senderNode->TraceConnectWithoutContext("Tx", MakeCallback (&SendAppTx));
- ApplicationContainer sinkApp;
- PacketSinkHelper sink = PacketSinkHelper (sock_factory, InetSocketAddress (Ipv4Address::GetAny (), 2000));
- sinkApp = sink.Install (rights);
- sinkApp.Start (Seconds (3.9999));
- Ptr<NetDevice> netQ = dev1.Get(0);
- PointerValue val;
- netQ->GetAttribute("TxQueue", val);
- Ptr<Queue> queue = val.Get<Queue>();
- Ptr<DropTailQueue> droptail = DynamicCast<DropTailQueue> (queue);
- AsciiTraceHelper ascii;
- Ptr<OutputStreamWrapper> stream = ascii.CreateFileStream(qSizeFileName);
- Simulator::Schedule(Seconds(0.0001), &routerQSize, queue, stream);
- Ptr<NetDevice> netDrop = dev1.Get(1);
- netDrop->TraceConnectWithoutContext ("PhyRxDrop", MakeCallback(&RxDrop));
- Ptr<NetDevice> senderND = dev0.Get(0);
- senderND->TraceConnectWithoutContext("PhyTxBegin", MakeCallback (&SenderTx));
- if (enablePcap){
- Simulator::Schedule(Seconds(pcapStartTime), &PcapScheduler, accessLeftLink, pcapFile, lefts);
- }
- Ptr<PacketSink> pkt_sink;
- for (int i = 0;i<m_nNodes-1;i++){
- Simulator::Schedule(Seconds(0.00001), &TraceCwnd, cwnd_tr_file);
- pkt_sink = sinkApp.Get(i)->GetObject<PacketSink>();
- Simulator::Schedule(Seconds(0.00001), &instTputCaller, instTput_file, pkt_sink, startTime, stopTime);
- }
- Simulator::Schedule (Seconds(0.001), &SimStatus);
- Simulator::Stop (Seconds (stopTime));
- Simulator::Run ();
- Ptr<PacketSink> pktsink;
- uint64_t total = 0;
- uint32_t queueDrops = droptail->GetTotalDroppedPackets();
- uint32_t queueRecvs = droptail->GetTotalReceivedPackets();
- for (int i = 0; i < m_nNodes; i++)
- {
- pktsink = sinkApp.Get (i)->GetObject<PacketSink> ();
- total += pktsink->GetTotalRx () ;
- }
- if (pktDebug){
- std::cout << "Total Sent packets by sender Application " << appcountDrops << std::endl;
- std::cout << "Total Sent packets by sender net device " << countTx << std::endl;
- std::cout << "Total Dropped Packets by router queue " << queueDrops << std::endl;
- std::cout << "Total Received Packets by router queue " << queueRecvs << std::endl;
- std::cout << "Total Corrupt Packets dropped at receiver " << countDrops << std::endl;
- std::cout << "Total packets received by receiver application " << total/m_pktSize << std::endl;
- for (int i = 0; i < m_nNodes; i++)
- {
- uint64_t total = 0;
- pktsink = sinkApp.Get (i)->GetObject<PacketSink> ();
- total = pktsink->GetTotalRx();
- std::cout << "Goodput of node " << i << transProt << " = " << total * 8 / (stopTime - startTime) << " bps" << std::endl;
- }
- }
- Simulator::Destroy ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement