Files

69 lines
1.8 KiB
C++
Raw Permalink Normal View History

2008-06-28 19:39:46 -07:00
/*
2024-06-17 16:17:10 +02:00
* SPDX-License-Identifier: GPL-2.0-only
2008-06-28 19:39:46 -07:00
*/
2022-10-07 20:08:35 +00:00
#include "ns3/applications-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
2022-10-07 20:08:35 +00:00
#include "ns3/network-module.h"
#include "ns3/point-to-point-module.h"
2008-06-28 19:39:46 -07:00
2020-02-02 16:46:50 +05:30
// Default Network Topology
//
// 10.1.1.0
// n0 -------------- n1
// point-to-point
//
2008-06-28 19:39:46 -07:00
using namespace ns3;
2022-10-07 20:08:35 +00:00
NS_LOG_COMPONENT_DEFINE("FirstScriptExample");
2008-06-28 19:39:46 -07:00
2011-05-13 15:35:31 -04:00
int
2022-10-07 20:08:35 +00:00
main(int argc, char* argv[])
2008-06-28 19:39:46 -07:00
{
2022-10-07 20:08:35 +00:00
CommandLine cmd(__FILE__);
cmd.Parse(argc, argv);
2022-10-07 20:08:35 +00:00
Time::SetResolution(Time::NS);
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
NodeContainer nodes;
nodes.Create(2);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
InternetStackHelper stack;
stack.Install(nodes);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
Ipv4AddressHelper address;
address.SetBase("10.1.1.0", "255.255.255.0");
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
Ipv4InterfaceContainer interfaces = address.Assign(devices);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
UdpEchoServerHelper echoServer(9);
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));
serverApps.Start(Seconds(1));
serverApps.Stop(Seconds(10));
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);
echoClient.SetAttribute("MaxPackets", UintegerValue(1));
echoClient.SetAttribute("Interval", TimeValue(Seconds(1)));
2022-10-07 20:08:35 +00:00
echoClient.SetAttribute("PacketSize", UintegerValue(1024));
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2));
clientApps.Stop(Seconds(10));
2008-06-28 19:39:46 -07:00
2022-10-07 20:08:35 +00:00
Simulator::Run();
Simulator::Destroy();
return 0;
2008-06-28 19:39:46 -07:00
}