2008-06-28 19:39:46 -07:00
|
|
|
/* -*- 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
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-18 16:05:39 -08:00
|
|
|
#include "ns3/core-module.h"
|
2011-02-21 09:11:37 -08:00
|
|
|
#include "ns3/network-module.h"
|
2008-06-28 19:39:46 -07:00
|
|
|
#include "ns3/helper-module.h"
|
2011-03-02 13:42:28 -08:00
|
|
|
#include "ns3/applications-module.h"
|
2008-06-28 19:39:46 -07:00
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
|
|
|
|
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
|
|
|
|
|
|
|
|
|
|
NodeContainer nodes;
|
|
|
|
|
nodes.Create (2);
|
|
|
|
|
|
|
|
|
|
PointToPointHelper pointToPoint;
|
2008-07-03 17:37:32 -07:00
|
|
|
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
|
|
|
|
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
2008-06-28 19:39:46 -07:00
|
|
|
|
|
|
|
|
NetDeviceContainer devices;
|
|
|
|
|
devices = pointToPoint.Install (nodes);
|
|
|
|
|
|
|
|
|
|
InternetStackHelper stack;
|
|
|
|
|
stack.Install (nodes);
|
|
|
|
|
|
|
|
|
|
Ipv4AddressHelper address;
|
|
|
|
|
address.SetBase ("10.1.1.0", "255.255.255.0");
|
|
|
|
|
|
|
|
|
|
Ipv4InterfaceContainer interfaces = address.Assign (devices);
|
|
|
|
|
|
2008-07-03 17:37:32 -07:00
|
|
|
UdpEchoServerHelper echoServer (9);
|
2008-06-28 19:39:46 -07:00
|
|
|
|
|
|
|
|
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
|
|
|
|
|
serverApps.Start (Seconds (1.0));
|
|
|
|
|
serverApps.Stop (Seconds (10.0));
|
|
|
|
|
|
2008-07-03 17:37:32 -07:00
|
|
|
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
|
|
|
|
|
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
|
|
|
|
|
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
|
|
|
|
|
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
|
2008-06-28 19:39:46 -07:00
|
|
|
|
|
|
|
|
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
|
|
|
|
|
clientApps.Start (Seconds (2.0));
|
|
|
|
|
clientApps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
Simulator::Run ();
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|