0% found this document useful (0 votes)
89 views9 pages

Bus Network Topology Simulation Guide

This document provides instructions for building a bus network topology simulation using NS-3 and analyzing the network traffic. It includes: 1. An explanation of the C++ source code used to set up the network simulation with 4 CSMA nodes connected in a bus topology via a point-to-point link. 2. Instructions for using Wireshark and tcpdump to analyze the pcap files capturing network traffic from the simulation. 3. Modifications to the code to enable visualization of the network using the NetAnim module, including positioning nodes.

Uploaded by

aiz15563
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)
89 views9 pages

Bus Network Topology Simulation Guide

This document provides instructions for building a bus network topology simulation using NS-3 and analyzing the network traffic. It includes: 1. An explanation of the C++ source code used to set up the network simulation with 4 CSMA nodes connected in a bus topology via a point-to-point link. 2. Instructions for using Wireshark and tcpdump to analyze the pcap files capturing network traffic from the simulation. 3. Modifications to the code to enable visualization of the network using the NetAnim module, including positioning nodes.

Uploaded by

aiz15563
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

2021/05/07

NST32031-Practical for Wireless Network


Department of ICT
Faculty of Technology
South Eastern University of Sri Lanka
Lab Sheet 03

Title: Building a Bus Network Topology


Source Code:
 it is saved inside your downloaded ns3 file example/tutorial location
 copy [Link] to ‘ns-330/scratch’ folder

Task 01: Source Code Explanation ([Link] or [Link]):


//Header files adding
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"

// Default Network Topology


// [Link]
// n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

// This groups all ns-3-related declarations in a scope outside the global namespace,
using namespace ns3;

//Doxygen documentation system. this line declares a logging component called


SecondScriptExample that allows you to enable and disable console message logging by
reference to the name.
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");

//Declaration of the main function of your program (script)


int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3; //unsigned integer 32bits
//number of csma nodes = 3
//n1 is point-to-point
CommandLine cmd;
[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma); // 3 csma
nodes
[Link] ("verbose", "Tell echo applications to log if true", verbose); //whatever we
are doing is recorded

[Link] (argc,argv);

if (verbose) //if verbose value is true boolean


{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
nCsma = nCsma == 0 ? 1 : nCsma; //if there is no nodes in csma, it takes at total node == 1

//Topology Helpers
//NodeContainer topology helper provides a convenient way to create, manage and access
any Node objects that we create in order to run a simulation
NodeContainer p2pNodes;
//point-to-point connection between n0 and n1
//asks the container to create two nodes.
[Link] (2);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma); //nCsma = 3

//constructing a point to point link


PointToPointHelper pointToPoint; //instantiates a PointToPointHelper object on the stack
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

//NetDeviceContainer holds a list of all of the NetDevice objects that are created
NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

InternetStackHelper stack;
[Link] ([Link] (0)); // [Link] ([Link] (1))there is no need to
install
[Link] (csmaNodes); //[Link](1)= [Link](0)
Ipv4AddressHelper address;
[Link] ("[Link]", "[Link]");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


//The server is [Link](3) - n4 is the server
[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (1));
[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps = [Link] ([Link] (0));


[Link] (Seconds (2.0)); //n0 is the client
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

[Link] ("second");
//pcap will be opened using either wireshark or tcpdump
[Link] ("second", [Link] (1), true);
//if you want to get packets to other nodes;
//[Link] ("second", [Link] (3), true);

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

To run this;
First copy paste [Link] to scratch folder. Then run below codes in terminal;

1. >> cd ns-allinone-3.30/
2. >> cd ns-3.30/
3. >>. /waf --run scratch/[Link]

Task 02: To implement network simulation using Wireshark;


 if you have not installed Wireshark follow below command
o >> sudo apt-get install wireshark

 here is the ‘.pcap’ files that were created inside ns3;

 run below code to see network simulation in Wireshark;


o >> wireshark [Link]
Task 03: To implement network simulation using tcpdump:
>> tcpdump –n –t –r [Link]

Task 04: To implement network simulation NetAnim to below changes:


#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/netanim-module.h"

using namespace ns3;


NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");

int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;

CommandLine cmd;
[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
[Link] ("verbose", "Tell echo applications to log if true", verbose);

[Link] (argc,argv);

if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
nCsma = nCsma == 0 ? 1 : nCsma;

NodeContainer p2pNodes;
[Link] (2);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

InternetStackHelper stack;
[Link] ([Link] (0));
[Link] (csmaNodes);
Ipv4AddressHelper address;
[Link] ("[Link]", "[Link]");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (3));
[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps = [Link] ([Link] (0));


[Link] (Seconds (2.0));
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

[Link] ("second");
[Link] ("second", [Link] (1), true);

//Network Animator
AnimationInterface anim(“[Link]”);
[Link]([Link](0), 10.0,10.0);
[Link]([Link](1), 20.0,20.0);
[Link]([Link](1), 30.0,30.0);
[Link]([Link](2), 40.0,40.0);
[Link]([Link](3), 50.0,50.0);

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

To run this;

1. ./waf –run scratch/second


2. cd ns-allinone-3.30/netaim-3.108/
3. /NetAnim

You might also like