0% found this document useful (0 votes)
20 views2 pages

1

This document is a C++ script using the NS-3 network simulator to create a simple network with three nodes connected by point-to-point links. It sets up a UDP echo server on one node and clients on the other two nodes, with specific configurations for data rate and delay. The simulation also includes an animation output to visualize the network topology and node positions.

Uploaded by

Vishwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

1

This document is a C++ script using the NS-3 network simulator to create a simple network with three nodes connected by point-to-point links. It sets up a UDP echo server on one node and clients on the other two nodes, with specific configurations for data rate and delay. The simulation also includes an animation output to visualize the network topology and node positions.

Uploaded by

Vishwa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#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 "ns3/netanim-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int main (int argc, char *argv[])


{
CommandLine cmd (__FILE__);
cmd.Parse (argc, argv);

Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer nodes;
nodes.Create (3);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

NetDeviceContainer devices01 = pointToPoint.Install (nodes.Get(0), nodes.Get(1));

NetDeviceContainer devices12 = pointToPoint.Install (nodes.Get(1), nodes.Get(2));

InternetStackHelper stack;
stack.Install (nodes);

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");

Ipv4InterfaceContainer interfaces01 = address.Assign (devices01);

address.SetBase ("10.1.2.0", "255.255.255.0");


Ipv4InterfaceContainer interfaces12 = address.Assign (devices12);

UdpEchoServerHelper echoServer (9);


ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient0 (interfaces01.GetAddress (1), 9);


echoClient0.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient0.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient0.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps0 = echoClient0.Install (nodes.Get (0));
clientApps0.Start (Seconds (2.0));
clientApps0.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient1 (interfaces12.GetAddress (1), 9);


echoClient1.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient1.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps1 = echoClient1.Install (nodes.Get (2));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (10.0));

Ptr<Node> n0 = nodes.Get(0);
Ptr<Node> n1 = nodes.Get(1);
Ptr<Node> n2 = nodes.Get(2);

AnimationInterface anim("output/myfirst.xml");
anim.SetConstantPosition(n0, 100, 800);
anim.SetConstantPosition(n1, 400, 800);
anim.SetConstantPosition(n2, 800, 800);

Simulator::Run ();
Simulator::Destroy ();
return 0;
}

You might also like