I need to use a tcp source instead of udp source used in the below code:
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
serverApps.Start (Seconds (0.0));
serverApps.Stop (Seconds (100));
UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(100*
(1/0.03))));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.03)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (22));
clientApps.Start (Seconds (30.0));
clientApps.Stop (Seconds (100));
UdpEchoServerHelper echoServer1 (25);
ApplicationContainer serverApps1 = echoServer1.Install (nodes.Get (4));
serverApps1.Start (Seconds (0.0));
serverApps1.Stop (Seconds (100));
UdpEchoClientHelper echoClient1 (interfaces.GetAddress (15), 25);
echoClient1.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(100*
(1/0.1))));
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.1)));
echoClient1.SetAttribute ("PacketSize", UintegerValue (512));
ApplicationContainer clientApps1 = echoClient1.Install (nodes.Get (22));
clientApps1.Start (Seconds (0.0));
clientApps1.Stop (Seconds (100));
I tried searching for replacing the udp with tcp source but i did not get any
proper solution in ns3 forums. Could anyone please help me out??
I have posted the complete code below:
#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/v4ping-helper.h"
#include "ns3/udp-echo-helper.h"
#include "ns3/config-store-module.h"
#include "ns3/athstats-helper.h"
#include <iostream>
#include <cmath>
#include <sstream>
#include <fstream>
using namespace ns3;
static bool g_verbose = true;
void
DevTxTrace1 (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
//std::cout << " TX p: " << *p << std::endl;
Time time = Simulator::Now ();
cout << "\n"<<time.GetSeconds() << " TX Packet " << "ID: " << p->GetUid()<< "
Size: " << p->GetSize() << endl;
}
}
void
DevRxTrace1 (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
//std::cout << " RX p: " << *p << std::endl;
Time time = Simulator::Now ();
cout << "\n"<<time.GetSeconds() << " RX Packet " << "ID: " << p->GetUid()<< "
Size: " << p->GetSize() << endl;
}
}
/**
* \brief Test script.
*
* This script creates 1-dimensional grid topology and then ping last node from
the first one:
*
* [10.0.0.1] <-- step --> [10.0.0.2] <-- step --> [10.0.0.3] <-- step -->
[10.0.04]
*
* ping 10.0.0.4
*/
class AodvExample
{
public:
AodvExample ();
/// Configure script parameters, \return true on successful configuration
bool Configure (int argc, char **argv);
/// Run simulation
void Run ();
/// Report results
void Report (std::ostream & os);
private:
///\name parameters
//\{
/// Number of nodes
uint32_t size;
/// Distance between nodes, meters
double step;
/// Simulation time, seconds
double totalTime;
/// Write per-device PCAP traces if true
bool pcap;
/// Print routes if true
bool printRoutes;
//\}
///\name network
//\{
NodeContainer nodes;
NetDeviceContainer devices;
Ipv4InterfaceContainer interfaces;
//\}
private:
void CreateNodes ();
void CreateDevices ();
void InstallInternetStack ();
void InstallApplications ();
};
int main (int argc, char **argv)
{
AodvExample test;
if (!test.Configure (argc, argv))
NS_FATAL_ERROR ("Configuration failed. Aborted.");
bool verbose = true;
uint32_t nWifi = 1;
CommandLine cmd;
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.Parse (argc,argv);
test.Run ();
test.Report (std::cout);
return 0;
}
//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
size (25),
step (60),
totalTime (100),
pcap (true),
printRoutes (true)
{
}
bool
AodvExample::Configure (int argc, char **argv)
{
// Enable AODV logs by default. Comment this if too noisy
//LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);
SeedManager::SetSeed (12345);
CommandLine cmd;
cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
cmd.AddValue ("printRoutes", "Print routing table dumps.", printRoutes);
cmd.AddValue ("size", "Number of nodes.", size);
cmd.AddValue ("time", "Simulation time, s.", totalTime);
cmd.AddValue ("step", "Grid step, m", step);
cmd.Parse (argc, argv);
return true;
}
void
AodvExample::Run ()
{
// Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
UintegerValue (1)); // enable rts cts all the time.
CreateNodes ();
CreateDevices ();
InstallInternetStack ();
InstallApplications ();
std::cout << "Starting simulation for " << totalTime << " s ...\n";
Simulator::Stop (Seconds (totalTime));
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx", MakeCallback
(&DevTxTrace1));
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx", MakeCallback
(&DevRxTrace1));
Simulator::Run ();
Simulator::Destroy ();
}
void
AodvExample::Report (std::ostream &)
{
}
void
AodvExample::CreateNodes ()
{
std::cout << "Creating " << (unsigned)size << " nodes " << step << " m
apart.\n";
nodes.Create (size);
// Name nodes
for (uint32_t i = 0; i < size; ++i)
{
std::ostringstream os;
os << "node-" << i;
Names::Add (os.str (), nodes.Get (i));
}
// Create static grid
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (step),
"DeltaY", DoubleValue (step),
"GridWidth", UintegerValue (5),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
}
void
AodvExample::CreateDevices ()
{
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.Set ("RxGain", DoubleValue (0) );
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) );
//beg add vignesh
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
//end add vignesh
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",
StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
devices = wifi.Install (wifiPhy, wifiMac, nodes);
if (pcap)
{
wifiPhy.EnablePcapAll (std::string ("aodv"));
}
}
void
AodvExample::InstallInternetStack ()
{
AodvHelper aodv;
// you can configure AODV attributes here using aodv.Set(name, value)
InternetStackHelper stack;
stack.SetRoutingHelper (aodv); // has effect on the next Install ()
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.0.0.0", "255.0.0.0");
interfaces = address.Assign (devices);
if (printRoutes)
{
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper>
("aodv.routes", std::ios::out);
aodv.PrintRoutingTableAllAt (Seconds (8), routingStream);
}
}
void
AodvExample::InstallApplications ()
{
/* V4PingHelper ping (interfaces.GetAddress (size - 1));
ping.SetAttribute ("Verbose", BooleanValue (true));
ApplicationContainer p = ping.Install (nodes.Get (0));
p.Start (Seconds (0));
p.Stop (Seconds (totalTime) - Seconds (0.001));
// move node away
Ptr<Node> node = nodes.Get (size/2);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob,
Vector (1e5, 1e5, 1e5));*/
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (0));
serverApps.Start (Seconds (0.0));
serverApps.Stop (Seconds (100));
UdpEchoClientHelper echoClient (interfaces.GetAddress (0), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(100*
(1/0.03))));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.03)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (22));
clientApps.Start (Seconds (30.0));
clientApps.Stop (Seconds (100));
UdpEchoServerHelper echoServer1 (25);
ApplicationContainer serverApps1 = echoServer1.Install (nodes.Get (4));
serverApps1.Start (Seconds (0.0));
serverApps1.Stop (Seconds (100));
UdpEchoClientHelper echoClient1 (interfaces.GetAddress (15), 25);
echoClient1.SetAttribute ("MaxPackets", UintegerValue ((uint32_t)(100*
(1/0.1))));
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (0.1)));
echoClient1.SetAttribute ("PacketSize", UintegerValue (512));
ApplicationContainer clientApps1 = echoClient1.Install (nodes.Get (22));
clientApps1.Start (Seconds (0.0));
clientApps1.Stop (Seconds (100));
}
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.