Created
November 16, 2012 07:36
-
-
Save avras/4085165 to your computer and use it in GitHub Desktop.
A number of UDP echo client/server pairs communicating with each other
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
/* | |
* 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 | |
*/ | |
#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 <ctime> | |
using namespace ns3; | |
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample"); | |
int | |
main (int argc, char *argv[]) | |
{ | |
time_t start, nodes_created, end; | |
time(&start); | |
bool verbose = true; | |
uint32_t numPairs = 1; | |
CommandLine cmd; | |
cmd.AddValue ("numPairs", "Number of pairs of nodes/devices", numPairs); | |
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose); | |
cmd.Parse (argc,argv); | |
if (verbose) | |
{ | |
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO); | |
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO); | |
} | |
NodeContainer nodes; | |
nodes.Create (2*numPairs); | |
Ipv4AddressHelper address; | |
address.SetBase ("10.0.0.0", "255.0.0.0"); | |
PointToPointHelper pointToPoint; | |
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); | |
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); | |
NetDeviceContainer devices; | |
InternetStackHelper stack; | |
stack.Install (nodes); | |
Ipv4InterfaceContainer interfaces; | |
UdpEchoServerHelper echoServer (9); | |
ApplicationContainer serverApps; | |
for (uint32_t i = 0; i < numPairs; i++) | |
{ | |
devices = pointToPoint.Install (nodes.Get(2*i), nodes.Get(2*i+1)); | |
interfaces = address.Assign (devices); | |
serverApps = echoServer.Install (nodes.Get (2*i+1)); | |
serverApps.Start (Seconds (1.0)); | |
serverApps.Stop (Seconds (3.0)); | |
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9); | |
echoClient.SetAttribute ("MaxPackets", UintegerValue (10000)); | |
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.1))); | |
echoClient.SetAttribute ("PacketSize", UintegerValue (1024)); | |
ApplicationContainer clientApps = echoClient.Install (nodes.Get (2*i)); | |
clientApps.Start (Seconds (2.0)); | |
clientApps.Stop (Seconds (3.0)); | |
} | |
time(&nodes_created); | |
double loadtime = difftime(nodes_created, start); | |
//pointToPoint.EnablePcapAll("myfirst"); | |
Simulator::Run (); | |
Simulator::Destroy (); | |
time(&end); | |
double endtime = difftime(end, start); | |
printf("Total Time = %.2lf seconds\n", endtime); | |
printf("Load Time = %.2lf seconds\n", loadtime); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry Sir Iam new to ns3
UdpEchoServerHelper echoServer (9); what does 9 represents here ?