0% found this document useful (0 votes)
59 views6 pages

Assignment 1 - 119CS0143

This program simulates a network with 5 nodes connected in a star topology via point-to-point links. It installs UDP echo client and server applications to enable communication between the nodes. The nodes and applications are configured, the simulation is run, and pcap traces and animations are output to analyze the results.

Uploaded by

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

Assignment 1 - 119CS0143

This program simulates a network with 5 nodes connected in a star topology via point-to-point links. It installs UDP echo client and server applications to enable communication between the nodes. The nodes and applications are configured, the simulation is run, and pcap traces and animations are output to analyze the results.

Uploaded by

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

Assignment 1 - 119CS0143

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

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");

int
main (int argc, char *argv[])
{
CommandLine cmd;
bool tracing = true;
cmd.Parse (argc, argv);
cmd.AddValue("tracing", "Enable pcap tracing", tracing);
Time::SetResolution (Time::NS);

LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);


LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer nodes;
nodes.Create (5);

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

NetDeviceContainer devices1;

Assignment 1 - 119CS0143 1
devices1 = pointToPoint.Install (nodes.Get (0), nodes.Get (1));
NetDeviceContainer devices2;
devices2 = pointToPoint.Install (nodes.Get (2), nodes.Get (1));
NetDeviceContainer devices3;
devices3 = pointToPoint.Install (nodes.Get (3), nodes.Get (1));
NetDeviceContainer devices4;
devices4 = pointToPoint.Install (nodes.Get (4), nodes.Get (1));

InternetStackHelper stack;
stack.Install (nodes);

Ipv4AddressHelper address1;
address1.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4AddressHelper address2;
address2.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4AddressHelper address3;
address3.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4AddressHelper address4;
address4.SetBase ("10.1.4.0", "255.255.255.0");

Ipv4InterfaceContainer interfaces1 = address1.Assign (devices1);


Ipv4InterfaceContainer interfaces2 = address2.Assign (devices2);
Ipv4InterfaceContainer interfaces3 = address3.Assign (devices3);
Ipv4InterfaceContainer interfaces4 = address4.Assign (devices4);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));


serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient1 (interfaces1.GetAddress (1), 90);


echoClient1.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient1.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient1.SetAttribute ("PacketSize", UintegerValue (1024));

UdpEchoClientHelper echoClient2 (interfaces2.GetAddress (1), 91);


echoClient2.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient2.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient2.SetAttribute ("PacketSize", UintegerValue (1024));

UdpEchoClientHelper echoClient3 (interfaces3.GetAddress (1), 92);


echoClient3.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient3.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient3.SetAttribute ("PacketSize", UintegerValue (1024));

UdpEchoClientHelper echoClient4 (interfaces4.GetAddress (1), 93);


echoClient4.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient4.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient4.SetAttribute ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps1 = echoClient1.Install (nodes.Get (0));


clientApps1.Start (Seconds (2.0));

Assignment 1 - 119CS0143 2
clientApps1.Stop (Seconds (9.0));

ApplicationContainer clientApps2 = echoClient2.Install (nodes.Get (2));


clientApps2.Start (Seconds (2.0));
clientApps2.Stop (Seconds (9.0));

ApplicationContainer clientApps3 = echoClient3.Install (nodes.Get (3));


clientApps3.Start (Seconds (2.0));
clientApps3.Stop (Seconds (9.0));

ApplicationContainer clientApps4 = echoClient4.Install (nodes.Get (4));


clientApps4.Start (Seconds (2.0));
clientApps4.Stop (Seconds (9.0));

AnimationInterface anim("anim1.xml");
anim.SetConstantPosition(nodes.Get (0), 60.0, 20.0);
anim.SetConstantPosition(nodes.Get (1), 40.0, 35.0);
anim.SetConstantPosition(nodes.Get (2), 50.0, 60.0);
anim.SetConstantPosition(nodes.Get (3), 20.0, 50.0);
anim.SetConstantPosition(nodes.Get (4), 20.0, 20.0);
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll(ascii.CreateFileStream("trace1.tr"));
if(tracing==true)
{
pointToPoint.EnablePcapAll("trace1");
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

Assignment 1 - 119CS0143 3
Assignment 1 - 119CS0143 4
Assignment 1 - 119CS0143 5
Assignment 1 - 119CS0143 6

You might also like