0% found this document useful (0 votes)
3 views

Research

Files
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Research

Files
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <string>

#include <fstream>
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
#include "ns3/network-module.h"
#include "ns3/packet-sink.h"
//step1: add the following header files
#include "ns3/flow-monitor.h"
#include "ns3/flow-monitor-helper.h"
#include "ns3/traffic-control-module.h"

using namespace ns3;

int main (int argc, char *argv[])


{

uint32_t maxBytes = 0;
NodeContainer nodes;
nodes.Create (2);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("500Kbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("5ms"));

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

InternetStackHelper internet;
internet.Install (nodes);

Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);

uint32_t port = 9;

BulkSendHelper source ("ns3::TcpSocketFactory",


InetSocketAddress (i.GetAddress (1),
port));
source.SetAttribute ("MaxBytes", UintegerValue (maxBytes));
ApplicationContainer sourceApps = source.Install (nodes.Get
(0));
sourceApps.Start (Seconds (0.0));
sourceApps.Stop (Seconds (10.0));

PacketSinkHelper sink ("ns3::TcpSocketFactory",


InetSocketAddress (Ipv4Address::GetAny
(), port));
ApplicationContainer sinkApps = sink.Install (nodes.Get (1));
sinkApps.Start (Seconds (0.0));
sinkApps.Stop (Seconds (10.0));

//step2: add the following code for Flow monitor


Ptr<FlowMonitor> flowMonitor;
FlowMonitorHelper flowHelper;
flowMonitor = flowHelper.InstallAll();

AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream
("5.tr"));

Simulator::Stop (Seconds (10.0));


Simulator::Run ();

//step 3: add the following statement for xml file


flowMonitor->SerializeToXmlFile("p16.xml", true, true);

Simulator::Destroy ();

Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (sinkApps.Get


(0));
std::cout << "Total Bytes Received: " << sink1->GetTotalRx ()
<< std::endl;
}

You might also like