2010-01-25 16:09:07 -08:00
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "tutorial-app.h"
|
|
|
|
|
|
|
|
|
|
#include "ns3/applications-module.h"
|
2010-01-25 16:09:07 -08:00
|
|
|
#include "ns3/core-module.h"
|
2011-02-25 10:32:35 -08:00
|
|
|
#include "ns3/internet-module.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
#include "ns3/network-module.h"
|
2022-01-30 11:14:47 -06:00
|
|
|
#include "ns3/point-to-point-module.h"
|
2022-10-07 20:08:35 +00:00
|
|
|
|
|
|
|
|
#include <fstream>
|
2010-01-25 16:09:07 -08:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NS_LOG_COMPONENT_DEFINE("SixthScriptExample");
|
2010-01-25 16:09:07 -08:00
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
//
|
|
|
|
|
// node 0 node 1
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
// | ns-3 TCP | | ns-3 TCP |
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
// | 10.1.1.1 | | 10.1.1.2 |
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
// | point-to-point | | point-to-point |
|
|
|
|
|
// +----------------+ +----------------+
|
|
|
|
|
// | |
|
|
|
|
|
// +---------------------+
|
|
|
|
|
// 5 Mbps, 2 ms
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// We want to look at changes in the ns-3 TCP congestion window. We need
|
|
|
|
|
// to crank up a flow and hook the CongestionWindow attribute on the socket
|
|
|
|
|
// of the sender. Normally one would use an on-off application to generate a
|
2013-08-28 18:45:56 -07:00
|
|
|
// flow, but this has a couple of problems. First, the socket of the on-off
|
|
|
|
|
// application is not created until Application Start time, so we wouldn't be
|
|
|
|
|
// able to hook the socket (now) at configuration time. Second, even if we
|
|
|
|
|
// could arrange a call after start time, the socket is not public so we
|
2010-01-25 16:09:07 -08:00
|
|
|
// couldn't get at it.
|
|
|
|
|
//
|
|
|
|
|
// So, we can cook up a simple version of the on-off application that does what
|
|
|
|
|
// we want. On the plus side we don't need all of the complexity of the on-off
|
|
|
|
|
// application. On the minus side, we don't have a helper, so we have to get
|
|
|
|
|
// a little more involved in the details, but this is trivial.
|
|
|
|
|
//
|
2013-08-28 18:45:56 -07:00
|
|
|
// So first, we create a socket and do the trace connect on it; then we pass
|
|
|
|
|
// this socket into the constructor of our simple application which we then
|
2010-01-25 16:09:07 -08:00
|
|
|
// install in the source node.
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
//
|
|
|
|
|
|
2022-08-28 13:24:25 -05:00
|
|
|
/**
|
|
|
|
|
* Congestion window change callback
|
|
|
|
|
*
|
|
|
|
|
* \param stream The ouput stream file.
|
|
|
|
|
* \param oldCwnd Old congestion window.
|
|
|
|
|
* \param newCwnd New congestion window.
|
|
|
|
|
*/
|
2010-01-25 16:09:07 -08:00
|
|
|
static void
|
2022-10-07 20:08:35 +00:00
|
|
|
CwndChange(Ptr<OutputStreamWrapper> stream, uint32_t oldCwnd, uint32_t newCwnd)
|
2010-01-25 16:09:07 -08:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
NS_LOG_UNCOND(Simulator::Now().GetSeconds() << "\t" << newCwnd);
|
|
|
|
|
*stream->GetStream() << Simulator::Now().GetSeconds() << "\t" << oldCwnd << "\t" << newCwnd
|
|
|
|
|
<< std::endl;
|
2010-01-25 16:09:07 -08:00
|
|
|
}
|
|
|
|
|
|
2022-08-28 13:24:25 -05:00
|
|
|
/**
|
|
|
|
|
* Rx drop callback
|
|
|
|
|
*
|
|
|
|
|
* \param file The ouput PCAP file.
|
|
|
|
|
* \param p The dropped packet.
|
|
|
|
|
*/
|
2010-01-25 16:09:07 -08:00
|
|
|
static void
|
2022-10-07 20:08:35 +00:00
|
|
|
RxDrop(Ptr<PcapFileWrapper> file, Ptr<const Packet> p)
|
2010-01-25 16:09:07 -08:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
NS_LOG_UNCOND("RxDrop at " << Simulator::Now().GetSeconds());
|
|
|
|
|
file->Write(Simulator::Now(), p);
|
2010-01-25 16:09:07 -08:00
|
|
|
}
|
|
|
|
|
|
2013-08-28 18:45:56 -07:00
|
|
|
int
|
2022-10-07 20:08:35 +00:00
|
|
|
main(int argc, char* argv[])
|
2010-01-25 16:09:07 -08:00
|
|
|
{
|
2022-10-07 20:08:35 +00:00
|
|
|
CommandLine cmd(__FILE__);
|
|
|
|
|
cmd.Parse(argc, argv);
|
2022-06-05 21:01:11 -07:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NodeContainer nodes;
|
|
|
|
|
nodes.Create(2);
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
PointToPointHelper pointToPoint;
|
|
|
|
|
pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
|
|
|
|
|
pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
NetDeviceContainer devices;
|
|
|
|
|
devices = pointToPoint.Install(nodes);
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<RateErrorModel> em = CreateObject<RateErrorModel>();
|
|
|
|
|
em->SetAttribute("ErrorRate", DoubleValue(0.00001));
|
|
|
|
|
devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em));
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
InternetStackHelper stack;
|
|
|
|
|
stack.Install(nodes);
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ipv4AddressHelper address;
|
|
|
|
|
address.SetBase("10.1.1.0", "255.255.255.252");
|
|
|
|
|
Ipv4InterfaceContainer interfaces = address.Assign(devices);
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
uint16_t sinkPort = 8080;
|
|
|
|
|
Address sinkAddress(InetSocketAddress(interfaces.GetAddress(1), sinkPort));
|
|
|
|
|
PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory",
|
|
|
|
|
InetSocketAddress(Ipv4Address::GetAny(), sinkPort));
|
|
|
|
|
ApplicationContainer sinkApps = packetSinkHelper.Install(nodes.Get(1));
|
|
|
|
|
sinkApps.Start(Seconds(0.));
|
|
|
|
|
sinkApps.Stop(Seconds(20.));
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<Socket> ns3TcpSocket = Socket::CreateSocket(nodes.Get(0), TcpSocketFactory::GetTypeId());
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Ptr<TutorialApp> app = CreateObject<TutorialApp>();
|
|
|
|
|
app->Setup(ns3TcpSocket, sinkAddress, 1040, 1000, DataRate("1Mbps"));
|
|
|
|
|
nodes.Get(0)->AddApplication(app);
|
|
|
|
|
app->SetStartTime(Seconds(1.));
|
|
|
|
|
app->SetStopTime(Seconds(20.));
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
AsciiTraceHelper asciiTraceHelper;
|
|
|
|
|
Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream("sixth.cwnd");
|
|
|
|
|
ns3TcpSocket->TraceConnectWithoutContext("CongestionWindow",
|
|
|
|
|
MakeBoundCallback(&CwndChange, stream));
|
2010-01-27 12:15:30 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
PcapHelper pcapHelper;
|
|
|
|
|
Ptr<PcapFileWrapper> file =
|
|
|
|
|
pcapHelper.CreateFile("sixth.pcap", std::ios::out, PcapHelper::DLT_PPP);
|
|
|
|
|
devices.Get(1)->TraceConnectWithoutContext("PhyRxDrop", MakeBoundCallback(&RxDrop, file));
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
Simulator::Stop(Seconds(20));
|
|
|
|
|
Simulator::Run();
|
|
|
|
|
Simulator::Destroy();
|
2010-01-25 16:09:07 -08:00
|
|
|
|
2022-10-07 20:08:35 +00:00
|
|
|
return 0;
|
2010-01-25 16:09:07 -08:00
|
|
|
}
|