2007-09-26 19:55:09 -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
|
|
|
|
|
*/
|
|
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
#include "ns3/core-module.h"
|
|
|
|
|
#include "ns3/simulator-module.h"
|
|
|
|
|
#include "ns3/helper-module.h"
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation");
|
|
|
|
|
|
|
|
|
|
using namespace ns3;
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO);
|
|
|
|
|
|
|
|
|
|
NS_LOG_INFO ("UDP Echo Simulation");
|
|
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
NodeContainer n;
|
|
|
|
|
n.Create (4);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
InternetStackHelper internet;
|
2008-04-07 10:38:37 -07:00
|
|
|
internet.Install (n);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
CsmaHelper csma;
|
2008-04-17 13:42:25 -07:00
|
|
|
csma.SetChannelParameter ("BitRate", StringValue ("5Mpbs"));
|
|
|
|
|
csma.SetChannelParameter ("Delay", StringValue ("2ms"));
|
2008-04-07 10:38:37 -07:00
|
|
|
NetDeviceContainer nd = csma.Install (n);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
Ipv4AddressHelper ipv4;
|
|
|
|
|
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
2008-04-07 10:41:21 -07:00
|
|
|
Ipv4InterfaceContainer i = ipv4.Assign (nd);
|
2007-09-26 19:55:09 -07:00
|
|
|
|
|
|
|
|
uint16_t port = 7;
|
|
|
|
|
|
2008-03-31 13:20:26 -07:00
|
|
|
UdpEchoClientHelper client;
|
|
|
|
|
client.SetRemote (i.GetAddress (1), port);
|
2008-04-17 13:42:25 -07:00
|
|
|
client.SetAppAttribute ("MaxPackets", UintegerValue (1));
|
|
|
|
|
client.SetAppAttribute ("Interval", StringValue ("1s"));
|
|
|
|
|
client.SetAppAttribute ("PacketSize", UintegerValue (1024));
|
2008-04-07 10:38:37 -07:00
|
|
|
ApplicationContainer apps = client.Install (n.Get (0));
|
2008-03-31 13:20:26 -07:00
|
|
|
apps.Start (Seconds (2.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
UdpEchoServerHelper server;
|
|
|
|
|
server.SetPort (port);
|
2008-04-07 10:38:37 -07:00
|
|
|
apps = server.Install (n.Get (1));
|
2008-03-31 13:20:26 -07:00
|
|
|
apps.Start (Seconds (1.0));
|
|
|
|
|
apps.Stop (Seconds (10.0));
|
|
|
|
|
|
|
|
|
|
std::ofstream os;
|
|
|
|
|
os.open ("tutorial.tr");
|
2008-04-22 21:18:04 -07:00
|
|
|
CsmaHelper::EnableAsciiAll (os);
|
2008-03-31 13:20:26 -07:00
|
|
|
|
2007-09-26 19:55:09 -07:00
|
|
|
Simulator::Run ();
|
|
|
|
|
Simulator::Destroy ();
|
|
|
|
|
}
|