0% found this document useful (0 votes)
12 views90 pages

Thiru Rec

Uploaded by

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

Thiru Rec

Uploaded by

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

VEL TECH HIGH TECH

Dr. RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE


(An Autonomous Institution)
(An ISO 9001-2008 CERTIFIED INSTITUTION)
Approved by AICTE New Delhi and Affliated to Anna University)
No.62 Avadi -- Veltech Road Chennai 600 062.

21HC57P-NETWORKS LABORATORY

NAME : SRINIVAS B

REGISTER NO :113022104147

ROLL NO :VH12423

BRANCH : B.E COMPUTER SCIENCE AND ENGINEERING

YEAR :2022-2026

SEMESTER :V

NAME: SRINIVAS B REG NO:113022104147


VEL TECH HIGH TECH
Dr. RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
(An Autonomous Institution)
(An ISO 9001-2008 CERTIFIED INSTITUTION)
Approved by AICTE New Delhi and Affliated to Anna Universi
No.62 Avadi -- Veltech Road Chennai 600 062

BONAFIDE CERTIFICATE
NAME: ........................................................................................................................YEAR: .......................

SEMESTER: ................................. BRANCH: B.E COMPUTER SCIENCE and ENGINEERING

UNIVERSITY REGISTER NO: ………………………………………………. VH NO: ……………………………………………………….

Certified that this is the bonafide record of work done by the above student in the

NETWORKS LABORATORY – 21HC57P during the academic year 2024 – 2025.

Signature of Lab Incharge Signature of Head of the Department

Submitted for the University Practical Examination held on at VEL TECH HIGH
TECH Dr. RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE,No.60, AVADI – ALAMATHI ROAD,
AVADI, CHENNAI -600 062.

Signature of Examiners:

Internal Examiner: ....................................... External Examiner: ...................................

NAME: SRINIVAS B REG NO:113022104147


DATE: ................................

VEL TECH HIGH TECH


Dr. RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE
VISION:

Pursuit of excellence in technical education to create civic responsibility with competency.

MISSION:

1. To impart the attributes of global engineers to face industrial challenges with social
relevance.
2. To indoctrinate as front runners through moral practices.
3. To attain the skills through lifelong learning.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING COLLEGE

VISION:

To blend academic learning process and innovative ideas producing self-confident graduates
with skills and knowledge to compete in the changing world.

MISSION:

● To provide strong basic knowledge in Computer Science and Engineering.

● To motivate the students to function as a team from their innovative ideas in


collaboration with the industries.

● To enable the students to lead and adapt to the growing environment.

NAME: SRINIVAS B REG NO:113022104147


PROGRAMME EDUCATIONAL OBJECTIVES

PEO-1:

Embark upon successful professional practice in Computer Science and Engineering,


displaying supportive and leadership roles.

PEO-2:

Engage in professional projects requiring teamwork and making valuable contributions to


design, development, and production in the practice of Computer Science and Engineering or
application areas.
PEO-3:
Equip to adapt and grow with changes in technology and globalization, and to pursue higher
studies and research activities.

PEO- 4:

Be capable of productive employment in the field of Computer Science and Engineering with
competing technical expertise, good interpersonal skill.

PEO-5:

Utilize their broad educational experience, ethics, and professionalism to make a positive
impact on their local and professional communities.

NAME: SRINIVAS B REG NO:113022104147


PROGRAMME OUTCOMES (POs):

PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, research literature, and analyze complex engineering
Problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research
Methods including design of experiments, analysis and interpretation of data, and synthesis of the
Information to provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write effective
reports and design documentation, make effective presentations, and give and receive clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

NAME: SRINIVAS B REG NO:113022104147


PROGRAM SPECIFIC OUTCOMES (PSOS)
By the time of graduation, the undergraduate Computer Science and Engineering students will have the
ability of

● Designing Computer/Electronic based components which would serve social


environment.

● Applying the current and gained knowledge and modern techniques not only in the
Computers but in all related fields.

COURSE OBJECTIVES:

● To learn and use network commands.


● To learn socket programming.
● To implement and analyze various network protocols.
● To learn and use simulation tools.
● To use simulation tools to analyze the performance of various network protocols

COURCE OUTCOME:

● Implement various protocols using TCP and UDP.


● Compare the performance of different transport layer protocols.
● Use simulation tools to analyze the performance of various network protocols.
● Analyze various routing algorithms.
● Implement error correction codes.

NAME: SRINIVAS B REG NO:113022104147


HARDWARE:

1. Standalone desktops 30 Nos

SOFTWARE:
1. C / C++ / Java / Python / Equivalent Compiler 30Nos
2. Network simulator like NS2/Glomosim/OPNET/ Packet Tracer / Equivalent

JAVA
Java is a high-level programming language originally developed by Sun
Microsystems. Java runs on a variety of platforms, such as Windows, Mac OS, and the
various versions of UNIX. Java programming were "Simple, Robust,
Portable,Platform-independent, Secured, High Performance, Multithreaded,
Architecture Neutral, Object-Oriented, Interpreted, and Dynamic".
NS2
NS2 stands for Network Simulator Version 2. It is an open-source event-driven
simulator designed specifically for research in computer communication networks. It
provides substantial support to simulate bunch of protocols like TCP, FTP, UDP, https
and DSR.It simulates wired and wireless network. It is primarily Unix Based. It uses
TCL as its scripting language.

NAME: SRINIVAS B REG NO:113022104147


CO-PO MATRIX

CO PO PO PO PO PO PO PO PO PO PO1 PO1 PO1


1 2 3 4 5 6 7 8 9 0 1 2

CS8581.1 3 2 - - - - - - - - -

CS8581.2 3 1 2 - - - - - - - - -

CS8581.3 - 2 - - - - - - -

CS8581.4 2 1 2 - - - - - - - - -

CS8581.5 3 1 1 - 2 - - - - - - -

CS8581 3 1 2 - 2 - - - - - - -

1 –Low 2 – Medium 3 – High

CO-PSO MATRIX

COURSE PSO 3

CS8581.1 2

CS8581.2 3

CS8581.3 3

CS8581.4 3

CS8581.5 2

CS8581 3

NAME: SRINIVAS B REG NO:113022104147


VEL TECH HIGH TECH
Dr. RANGARAJAN Dr. SAKUNTHALA ENGINEERING COLLEGE
An Autonomous Institution

Approved by AICTE-New Delhi, Affiliated to Anna University, Chennai

Accredited by NBA, New Delhi & Accredited by NAAC with “A” Grade & CGPA of 3.27

Course code 21HC57P Semester V


Category PROFESSIONAL CORE COURSE (PCC) L T P C
NETWORKS LABORATORY
Course Title 0 0 4 2
(Common to CSE & IT)

COURSE OBJECTIVES:
 To learn and use network commands.
 To learn socket programming.
 To implement and analyze various network protocols.
 To learn and use simulation tools.
 To use simulation tools to analyze the performance of various network protocols.
PREREQUISITE:

 Programming Knowledge of C and Java.

COURSE OUTCOMES:

CO. No. Course Outcomes Blooms level


On successful completion of this Course, students will be able to
C507.1 Implement various protocols using TCP and UDP. K3
C507.2 Compare the performance of different transport layer protocols K3
C507.3 Use simulation tools to analyze the performance of various K3
C507.4 Analyze various routing algorithms. K3
C507.5 Implement error correction codes. K3

COURSE OUTCOMES MAPPING WITH PROGRAM OUTCOMES AND PROGRAM SPECIFIC OUTCOMES

CO No. PO-1 PO-2 PO-3 PO-4 PO-5 PO-6 PO-7 PO-8 PO-9 PO-10 PO-11 PO- PSO-1 PSO-2
12
C507.1 3 3 1 - - - - - - - - - 3 2
C507.2 3 2 1 - - - - - - - - - 3 2
C507.3 3 2 1 - - - - - - - - - 3 2
C507.4 3 2 1 - - - - - - - - - 3 2
C507.5 3 2 1 - - - - - - - - - 3 2
Note: - 1: Slight 2: Moderate 3: Substantial

NAME: SRINIVAS B REG NO:113022104147


SYLLABUS No. of Credits: 2

LIST OF EXPERIMENTS

1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and


traceroute.
2. Capture ping and traceroute PDUs using a network protocol analyzer and
examine.
3. Write a HTTP web client program to download a web page using TCP sockets.
4. Applications using TCP sockets like:
(i) Echo client and echo server
(ii) Chat
(iii) File Transfer
5. Simulation of DNS using UDP sockets.
6. Write a code simulating ARP /RARP protocols.
7. Traffic Analysis using Wireshark.
8. Study of Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
9. Study of TCP/UDP performance using Simulation tool.
10. Simulation of Distance Vector / Link State Routing algorithm.
11. Performance evaluation of Routing protocols using Simulation tool.
12. Simulation of error correction code (like CRC).
13. Simulation of RIP and OSPF using NS2/Qualnet/JSim/OmneT++.

Total: 60 Periods

LEARNING RESOURCES:

TEXT BOOKS:

1. Behrouz A. Forouzan, Data Communications and Networking, Fifth Edition


TMH, 2013
2. William Stallings, Data and Computer Communications, Tenth Edition, Pearson
Education, 2013.

REFERENCES:

1. Larry L. Peterson, Bruce S. Davie, Computer Networks: A Systems


Approach, Fifth Edition, Morgan Kaufmann Publishers Inc., 2012.
2. Nader F. Mir, Computer and Communication Networks, Second
Edition, Prentice Hall, 2014.
3. Ying-Dar Lin, Ren-Hung Hwang and Fred Baker, Computer Networks: An
Open Source Approach, McGraw Hill Publisher, 2011.

NAME: SRINIVAS B REG NO:113022104147


LIST OF EXPERIMENTS
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup, and
traceroute.
2. Capture ping and traceroute PDUs using a network protocol analyzer and
examine.
3. Write an HTTP web client program to download a web page using TCP sockets.
4. Applications using TCP sockets like:
a. Echo client and echo server
b. Chat
c. File Transfer
5. Simulation of DNS using UDP sockets.
6. Write a code simulating ARP /RARP protocols.
Traffic Analysis using Wireshark.
7. Study of Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9. Simulation of Distance Vector / Link State Routing algorithm.
10. Performance evaluation of Routing protocols using Simulation tool.
11. Simulation of error correction code (like CRC).
12. Simulation of RIP and OSPF using NS2/Qualnet/JSim/OmneT++.

NAME: SRINIVAS B REG NO:113022104147


PAGE
S.NO DATE EXPERIMENT NAME SIGN
NO

NAME: SRINIVAS B REG NO:113022104147


Ex.No:1 BASIC NETWORK COMMANDS
Date : 22/7/24
Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute.

AIM: To learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute
ping.

COMMANDS:

1.tcpdump:

tcpdump is a most powerful and widely used command-line packets sniffer or package
analyzer tool which is used to capture or filter TCP/IP packets that received or transferred
over a network on a specificinterface. Display traffic between 2 hosts

2.netstat

Netstat is a common command line TCP/IP networking available in most versions


ofWindows, Linux, UNIX and other operating systems.Netstat provides information and
statistics about protocols in use and current TCP/IP networkconnections. The Windows help
to displays protocol statistics and current TCP/IP network connections.

#netstat

3. ipconfig

In Windows, ipconfig is a console application designed to run from the Windows command

prompt. This utility allows you to get the IP address information of a Windows computer.

Using ipconfigFrom the command prompt, type ipconfig to run the utility with default
options. The output of thedefault command contains the IP address, network mask, and
gateway for all physical and virtualnetwork adapter.

#ipconfig

4.nslookup

The nslookup (which stands for name server lookup) command is a network utility program
usedto obtain information about internet servers. It finds name server information for
domains by queryingthe Domain Name System.The nslookup command is a powerful tool for
diagnosing DNS problems.

#nslookup

5.tracert:

Traceroute uses Internet Control Message Protocol (ICMP) echo packets with variable time
to live(TTL) values. The response time of each hop is calculated.

NAME: SRINIVAS B REG NO:113022104147


#tracert google.com

6.Ping:

The ping command sends an echo request to a host available on the network. Using this
command,you can check if your remote host is responding well or not. Tracking and isolating
hardware andsoftware problems. Determining the status of the network and various foreign
hosts. The pingcommand is usually used as a simple way to verify that a computer can
communicate over the networkwith another computer or network device.

# ping172.16.6.2

7.hostname:

This is the simplest of all TCP/IP commands. It simply displays the name of your
computer.

#hostname

8. ipconfig /all

This command displays detailed configuration information about your TCP/IP connection
including Router, Gateway, DNS, DHCP, and type of Ethernet adapter in your system.

#ipconfig /all

9. pathping
Pathping is unique to Window’s, and is basically a combination of the Ping and
Tracert commands. Pathping traces the route to the destination address then
launches a 25 second test of each router along the way, gathering statistics on the
rate of data loss along each hop.

#pathping

10.route

The route command displays the computers routing table. A typical computer, with a single
network interface, connected to a LAN, with a router is fairly simple and generally doesn’t
pose any network problems. But if you’re having trouble accessing other computers on your
network, you can use the route command to make sure the entries in the routing table are
correct.

#route

NAME: SRINIVAS B REG NO:113022104147


OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Ex.No:2 a PROGRAM FOR PING

Date : 03/08/24

Capture ping and traceroute PDUs using a network protocol analyser and examine.

AIM: To write a socket program for PING in Java.

ALGORITHM:

1. Start the program.

2. Import Javautil and all necessary packages.

3. Initialize the ping server with socket as null value.

4. Get the IP address of the server using Scanner class.

5. Using get run time () method, executes the specified command in a separate process.

6. Stop the program.

PROGRAM:

importjava.util.*;

public class PingDemo

public void Ping(String host)

try

/* Process class provides methods for performing input from the process, performing output
to the process. class Runtime that allows the application to interface with the environment in
which the application is running. getRuntime-Returns the runtime object . getInputStream()
method gets the input stream of the subprocess */

Process p=Runtime.getRuntime().exec("Ping "+host);

Scanner scan=new Scanner(p.getInputStream());

while(scan.hasNextLine())

System.out.println(scan.nextLine());

NAME: SRINIVAS B REG NO:113022104147


}

catch(Exception ex)

System.out.println("error"+ex);

public static void main(String args[])

PingDemo P1=new PingDemo();

P1.Ping(args[0]);

OUTPUT:

Result:

Ex.No:2 b PROGRAM FOR TRACE ROUTE

NAME: SRINIVAS B REG NO:113022104147


Date : 03/08/24

AIM: To write a socket program for TRACE ROUTE in Java.

ALGORITHM:

Server

1. Start the program.

2. Import necessary packages.

3. Initialize the ping server with both sockets as null value.

4. Start the server socket.

5. At the client give the IP address of the server.

6. The client program is then started by starting socket.

7. At the receiver end, the client is pinged.

8. Stop the program.

Client

1. Start the program.

2. Import necessary packages.

3. Initialize the ping client with both sockets as null value.

4. Start the socket.

5. Get the IP address of the server.

PROGRAM:

Client Program

import java.io.*;

import java.net.*;

importjava.util.Calendar;

class pingClient

public static void main(String args[])throws Exception

NAME: SRINIVAS B REG NO:113022104147


{

String str;

int c=0;

long t1,t2;

Socket s=new Socket("127.0.0.1",5555);

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

while(c<4)

t1=System.currentTimeMillis();

str="Welcome to network programming world";

out.println(str);

System.out.println(dis.readLine());

t2=System.currentTimeMillis();

System.out.println(";TTL="+(t2-t1)+"ms"); c++;

s.close();

Server Program

import java.io.*;

import java.net.*;

importjava.util.*;

importjava.text.*;

class pingServer

public static void main(String args[])throws Exception

NAME: SRINIVAS B REG NO:113022104147


{

ServerSocketss=new ServerSocket(5555); Socket

s=ss.accept();

int c=0;

while(c<4)

DataInputStream dis=new DataInputStream(s.getInputStream());

PrintStream out=new PrintStream(s.getOutputStream());

String str=dis.readLine();

out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length()); c++;

s.close();

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Ex.No:3 DOWNLOAD A WEB PAGE USING TCP SOCKET

Date : 06/08/24

Write a HTTP web client program to download a web page using TCP sockets

Aim:
To write a java program for download a web page using TCP Socket.

Algorithm:
1.Start the program
2.Provide the address of the web page, which can be downloaded.
3.Get the information of the web page using the socket method.
4.Download the corresponding web page.
Aim:
To write a java program for download a web page using TCP Socket.

Algorithm:
1.Start the program
2.Provide the address of the web page, which can be downloaded.
3.Get the information of the web page using the socket method.
4.Download the corresponding web page.
Aim:
To write a java program for download a web page using TCP Socket.
AIM: To write a java program for download a webpage using TCP Scoket.

ALGORITHM:

1. Start the Program


2. Provide the address of the webpage which can be downloaded
3. Get the information of the web page using the socket method
4. Download the corresponding web page
5. Stop the Program

PROGRAM:

import java.io.*;

import java.net.*;

public class ruff

public static void main(String args[]) throws Exception

InetAddress add=InetAddress.getByName("www.google.com");

Socket s=new Socket(add,80);

NAME: SRINIVAS B REG NO:113022104147


boolean flag=true;

PrintWriter out=new PrintWriter(s.getOutputStream(),flag);

BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));

out.println("GET / HTTP/1.1");

out.println("Host:www.google.com:80");

out.println("Connection:Close");

out.println();

boolean loop=true;

StringBuilder sb=new StringBuilder(8096);

while(loop)

if(in.ready())

int i=0;

while(i!=-1)

i=in.read();

sb.append((char)i);

loop=false;

System.out.println(sb.toString());

s.close();

OUTPUT :

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Ex.No:4 a ECHO CLIENT AND ECHO SERVER USING SOCKET

Date: 13.08.24

Applications using TCP sockets like: Echo client and echo server

AIM :To write a java program for Echo client and echo server using socket.

ALGORITHM:

Client

1. Start

2. Create the TCP socket

3. Establish connection with the server

4. Get the message to be echoed from the user

5. Send the message to the server

6. Receive the message echoed by the server

7. Display the message received from the server

8. Terminate the connection

9. Stop

Server

1. Start

NAME: SRINIVAS B REG NO:113022104147


2. Create TCP socket, make it a listening socket

3. Accept the connection request sent by the client for connection establishment

4. Receive the message sent by the client

5. Display the received message

6. Send the received message to the client from which it receives

7. Close the connection when client initiates termination and server becomes a listening
server, waiting for clients.

8. Stop.

PROGRAM:

Client Program

import java.net.*;

import java.io.*;

public class EClient

public static void main(String arg[])

Socket c=null;

String line;

DataInputStream is,is1;

PrintStream os;

try

InetAddress ia = InetAddress.getLocalHost();

c=new Socket(ia,9000);

NAME: SRINIVAS B REG NO:113022104147


catch(IOException e)

System.out.println(e);

try

os=new PrintStream(c.getOutputStream());

is=new DataInputStream(System.in);

is1=new DataInputStream(c.getInputStream());

while(true)

System.out.println("Client:");

line=is.readLine();

os.println(line);

System.out.println("Server:" + is1.readLine());

catch(IOException e)

System.out.println("Socket Closed!");

Server Program

import java.net.*;

import java.io.*;

public class EServer

NAME: SRINIVAS B REG NO:113022104147


{

public static void main(String args[])

ServerSocket s=null;

String line;

DataInputStream is;

PrintStream ps;

Socket c=null;

try

s=new ServerSocket(9000);

catch(IOException e)

System.out.println(e);

try

c=s.accept();

is=new DataInputStream(c.getInputStream());

ps=new PrintStream(c.getOutputStream());

while(true)

line=is.readLine();

ps.println(line);

NAME: SRINIVAS B REG NO:113022104147


catch(IOException e)

System.out.println(e);

OUTPUT :

NAME: SRINIVAS B REG NO:113022104147


Result:

Ex.No: 4b CHAT PROGRAM USING SOCKET

Date: 13.08.24

Applications using TCP sockets like: Chat

AIM: To write a client-server application for chat using TCP

ALGORITHM:

Client

1. Start the program

2. Include necessary package in java

3. To create a socket in client to server.

4. The client establishes a connection to the server.

5. The client accept the connection and to send the data from client to server.

6. The client communicates the server to send the end of the message

7. Stop the program.

Server

1. Start the program

2. Include necessary package in java

NAME: SRINIVAS B REG NO:113022104147


3. To create a socket in server to client

4. The server establishes a connection to the client.

5. The server accept the connection and to send the data from server to client and vice versa

7. The server communicates the client to send the end of the message.

8. Stop the program.

PROGRAM:

Client Program

import java.net.*;

import java.io.*;

public class TCPclient

public static void main(String args[])

Socket c=null;

String line;

DataInputStream is,is1;

PrintStream os;

try

c=new Socket("localhost",9999);

catch(IOException e)

System.out.println(e);

try

NAME: SRINIVAS B REG NO:113022104147


os=new PrintStream(c.getOutputStream());

is=new DataInputStream(System.in);

is1=new DataInputStream(c.getInputStream());

do

System.out.println("Client:");

line=is.readLine();

os.println(line);

System.out.println("Server:" + is1.readLine());

while(line.equalsIgnoreCase("quit")==false);

is1.close();

os.close();

catch(IOException e)

System.out.println("SocketClosed!Message Passing is over");

Server Program

import java.net.*;

import java.io.*;

public class TCPserver

public static void main(String args[])

NAME: SRINIVAS B REG NO:113022104147


ServerSocket s=null;

String line;

DataInputStream is=null,is1=null;

PrintStream os=null;

Socket c=null;

try

s=new ServerSocket(9999);

catch(IOException e)

System.out.println(e);

try

c=s.accept();

is=new DataInputStream(c.getInputStream());

is1=new DataInputStream(System.in);

os=new PrintStream(c.getOutputStream());

do

line=is.readLine();

System.out.println("Client:"+line);

System.out.println("Server:");

line=is1.readLine();

os.println(line);

NAME: SRINIVAS B REG NO:113022104147


}

while(line.equalsIgnoreCase("quit")==false);

is.close();

os.close();

catch(IOException e)

System.out.println(e);

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

Ex.No:4c FILE TRANSFER USING SOCKET

Date: 13.08.24

Applications using TCP sockets like : File Transfer

AIM:To Perform File Transfer in Client & Server Using TCP/IP.

ALGORITHM:

Client

1. Start.

2. Establish a connection between the Client and Server.

3. Socket sock = new Socket( "127.0.0.1", 4000);

4. Implement a client that can send two requests.

NAME: SRINIVAS B REG NO:113022104147


i) To get a file from the server.

ii) To send a file name to the server.

5. After getting approval from the server ,the client get the content of the file from the server

6. Close the connection to the server.

7. Stop.

Server

1. Start.

2. Implement a server socket that listens to a particular port number.

3. Server reads the filename and sends the data stored in the file for the‘get’ request.

4. It reads the data from the input stream and writes it to a file in theserver for the ‘put’

instruction.

5. Exit upon client’s request.

6. Stop.

PROGRAM:

Client Program

import java.net.*;

import java.io.*;

public class client1

public static void main( String args[ ] ) throws Exception

Socket sock = new Socket( "127.0.0.1", 4000);

// reading the file name from keyboard. Uses input stream

System.out.print("Enter the file name : ");

NAME: SRINIVAS B REG NO:113022104147


BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));

String fname = keyRead.readLine();

// sending the file name to server. Uses PrintWriter

OutputStream ostream = sock.getOutputStream( );

PrintWriter pwrite = new PrintWriter(ostream, true);

pwrite.println(fname);

// receiving the contents from server. Uses input stream

InputStream istream = sock.getInputStream();

BufferedReader socketRead = new BufferedReader(new InputStreamReader(istream));

String str;

while((str = socketRead.readLine()) != null) // reading line-by-line

System.out.println(str);

pwrite.close(); socketRead.close(); keyRead.close();

Server Program

import java.net.*;

import java.io.*;

public class server1

public static void main(String args[]) throws Exception

{ // establishing the connection with the server

ServerSocket sersock = new ServerSocket(4000);

System.out.println("Server ready for connection");

Socket sock = sersock.accept(); // binding with port: 4000

NAME: SRINIVAS B REG NO:113022104147


System.out.println("Connection is successful");

// reading the file name from client

InputStream istream = sock.getInputStream( );

BufferedReader fileRead =new BufferedReader(new InputStreamReader(istream));

String fname = fileRead.readLine( );

// reading file contents

BufferedReader contentRead = new BufferedReader(new FileReader(fname) );

// keeping output stream ready to send the contents

OutputStream ostream = sock.getOutputStream( );

PrintWriter pwrite = new PrintWriter(ostream, true);

String str;

while((str = contentRead.readLine()) != null) // reading line-by-line from file

pwrite.println(str); // sending each line to client

sock.close(); sersock.close(); // closing network sockets

pwrite.close(); fileRead.close(); contentRead.close();

input.txt

Srinivas

Subramani

Tamizharasi

Sukumar

Sowmiya

NAME: SRINIVAS B REG NO:113022104147


Umashankar

Thejasri

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Ex. No: 5 SIMULATION OF DNS USING UDP SOCKETS

Date: 09.09.24

AIM: To write a program to Simulation of DNS using UDP sockets.

ALGORITHM:

Client

1. Start the program

2. Include necessary package in java

3. To create a socket in client to server.

4. The client establishes a connection to the server.

5. The client accept the connection and to send the host name from client to server.

6. The client communicates the server to get the ip address from the relevant host name

7. Stop the program.

Server

1. Start the program

2. Include necessary package in java

3. Argument is passed as the host name

4. Relevant host name with ip address are get in the array

5. To create a socket in server to client

6. The server establishes a connection to the client.

7. The server accept the connection and to send the ip address to client

7. The server communicate the client to send the end of the message.

8. Stop the program.

PROGRAM:

Client Program

import java.io.*;

import java.net.*;

public class Dnsclient

NAME: SRINIVAS B REG NO:113022104147


{

public static void main(String args[])throws IOException

byte[] senddata1 = new byte[1024];

byte[] receivedata = new byte[1024];

int portaddr = 1362;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

DatagramSocket clientsocket = new DatagramSocket();

InetAddress ipaddress;

if (args.length == 0)

ipaddress = InetAddress.getLocalHost();

else

ipaddress = InetAddress.getByName(args[0]);

System.out.print("Enter the hostname: ");

String sentence = br.readLine();

senddata1 = sentence.getBytes();

DatagramPacket pack = new DatagramPacket(senddata1,senddata1.length, ipaddress,


portaddr);

clientsocket.send(pack);

DatagramPacket recvpack =new DatagramPacket(receivedata,receivedata.length);

clientsocket.receive(recvpack);

String modified = new String(recvpack.getData());

System.out.println("IP Address:"+ modified);

clientsocket.close();

Server Program

NAME: SRINIVAS B REG NO:113022104147


import java.io.*;

import java.net.*;

public class Dnsserver

private static int indexOf(String[] array, String str)

str = str.trim();

for (int i=0; i<array.length; i++)

if (array[i].equals(str)) return i;

return -1;

public static void main(String arg[])throws IOException

String[] hosts = {"yahoo.com","gmail.com","facebook.com"};

String[] ip = {"68.180.206.184", "209.85.148.19","169.63.189.16"};

System.out.println("Press Ctrl + C to Quit");

while (true)

DatagramSocket serversocket=new DatagramSocket(1362);

byte[] senddata = new byte[1021];

byte[] receivedata = new byte[1021];

DatagramPacket recvpack = new DatagramPacket(receivedata, receivedata.length);

serversocket.receive(recvpack);

String sen = new String(recvpack.getData());

InetAddress ipaddress = recvpack.getAddress();

NAME: SRINIVAS B REG NO:113022104147


int port = recvpack.getPort();

String capsent;

System.out.println("Request for host" + sen);

if(indexOf (hosts, sen) != -1)

capsent = ip[indexOf(hosts, sen)]; else capsent = "Host Not Found";

senddata = capsent.getBytes();

DatagramPacket pack = new DatagramPacket (senddata, senddata.length,ipaddress,port);

serversocket.send(pack);

serversocket.close();

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Ex.No:6a SIMULATION OF ARP PROTOCOL

Date: 16.09.24

AIM: To write a java program for simulating ARP protocols using TCP.

ALGORITHM:

Client

1. Start the program

2. Using socket connection is established between client and server.

3. Get the IP address to be converted into MAC address.

4. Send this IP address to server.

5. Server returns the MAC address to client.

6. Stop the Program.

Server

1. Start the program

2. Accept the socket which is created by the client.

3. Server maintains the table in which IP and corresponding MAC addresses are

stored.

4. Read the IP address which is send by the client.

5. Map the IP address with its MAC address and return the MAC address to client

6. Stop the Program

PROGRAM:

Client Program

import java.io.*;

import java.net.*;

import java.util.*;

class Clientarp

public static void main(String args[]) throws IOException

NAME: SRINIVAS B REG NO:113022104147


{

try

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

Socket s=new Socket("localhost",6666);

DataInputStream din=new DataInputStream(s.getInputStream());

DataOutputStream dout=new DataOutputStream(s.getOutputStream());

System.out.print("Enter the Logical address(IP) : ");

String str1=in.readLine();

dout.writeBytes(str1+'\n');

String str=din.readLine();

System.out.println("The Physical Address is : "+str);

s.close();

catch (Exception e)

System.out.println(e);

Server Program

import java.io.*;

import java.net.*;

import java.util.*;

class Serverarp

public static void main(String args[])

NAME: SRINIVAS B REG NO:113022104147


{

try

ServerSocket obj=new ServerSocket(6666);

Socket obj1=obj.accept();

while(true)

DataInputStream din=new DataInputStream(obj1.getInputStream());

DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());

String str=din.readLine();

String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};

String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};

for(int i=0;i<ip.length;i++)

if(str.equals(ip[i]))

dout.writeBytes(mac[i]+'\n');

break;

obj.close();

catch(Exception e)

System.out.println(e);

NAME: SRINIVAS B REG NO:113022104147


}

OUTPUT:

Result:

NAME: SRINIVAS B REG NO:113022104147


Ex.No:6b SIMULATION OF RARP PROTOCOL

Date: 16.09.24

AIM: To write a java program for simulating RARP protocols using UDP.

ALGORITHM:

Client

1.Start the program

2. using datagram sockets UDP function is established.

3.Get the MAC address to be converted into IP address.

4.Send this MAC address to server.

5.Server returns the IP address to client.

6. Stop the Program.

Server

1. Start the program

2. Server maintains the table in which IP and corresponding MAC addresses are

stored.

3. Read the MAC address which is send by the client.

4. Map the IP address with its MAC address and return the IP address to client.

5. Stop the Program

PROGRAM:

Client Program

import java.io.*;

import java.net.*;

import java.util.*;

class Clientrarp

public static void main(String args[])

NAME: SRINIVAS B REG NO:113022104147


try

DatagramSocket client=new DatagramSocket();

InetAddress addr=InetAddress.getByName("localhost");

byte[] sendbyte=new byte[1024];

byte[] receivebyte=new byte[1024];

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the Physical address (MAC) : ");

String str=in.readLine();

sendbyte=str.getBytes();

DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,8888);

client.send(sender);

DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);

client.receive(receiver);

String s=new String(receiver.getData());

System.out.println("The Logical Address is(IP): "+s);

client.close();

catch(Exception e)

System.out.println(e);

Server Program

import java.io.*;

import java.net.*;

NAME: SRINIVAS B REG NO:113022104147


import java.util.*;

class Serverrarp

public static void main(String args[])

try

DatagramSocket server=new DatagramSocket(8888);

while(true)

byte[] sendbyte=new byte[1024];

byte[] receivebyte=new byte[1024];

DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);

server.receive(receiver);

String str=new String(receiver.getData());

String s=str.trim();

InetAddress addr=receiver.getAddress();

int port=receiver.getPort();

String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};

String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};

for(int i=0;i<ip.length;i++)

if(s.equals(mac[i]))

sendbyte=ip[i].getBytes();

DatagramPacket sender=new DatagramPacket(sendbyte,sendbyte.length,addr,port);

server.send(sender);

NAME: SRINIVAS B REG NO:113022104147


break;

break;

catch(Exception e)

System.out.println(e);

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:

NAME: SRINIVAS B REG NO:113022104147


Traffic Analysis
using
Wireshark

NAME: SRINIVAS B REG NO:113022104147


Ex.No: 7. Study of Network Simulator (NS) and Simulation of Congestion Control
Date: 25.09.24 Algorithms using NS

AIM:
To Study Network simulator (NS) and Simulation of Congestion Control Algorithms
using NS

THEORY:

Network Simulator (Version 2), widely known as NS2, is simply an event-driven


simulation tool that has proved useful in studying the dynamic nature of communication
networks. The simulation of wired and wireless network functions and protocols (e.g., routing
algorithms, TCP, UDP) can be done using NS2. In general, NS2 provides users with a way of
specifying such network protocols and simulating their corresponding behaviors. Due to its
flexibility and modular nature, NS2 has gained constant popularity in the working research
community since its birth in 1989.

Basic Architecture of NS2:

The above figure shows the basic architecture of NS2. NS2 provides users with an
executable command ns which takes on input argument, the name of a Tcl simulation
scripting file. Users are feeding the name of a Tcl simulation script (which sets up a
simulation) as an input argument of an NS2 executable command ns.

In most cases, a simulation trace file is created, and is used to plot graph and/or to
create animation. NS2 consists of two key languages: C++ and Object-oriented Tool
Command Language (OTcl). While the C++ defines the internal mechanism (i.e., a backend)
of the simulation objects, the OTcl sets up simulation by assembling and configuring the
objects as well as scheduling discrete events (i.e., a frontend).

The C++ and the OTcl are linked together using TclCL. Mapped to a C++ object,
variables in the OTcl domains are sometimes referred to as handles. Conceptually, a handle
(e.g., n as a Node handle) is just a string (e.g.,_o10) in the OTcl domain, and does not contain
any functionality. instead, the functionality (e.g., receiving a packet) is defined in the mapped
C++ object (e.g., of class Connector). In the OTcl domain, a handle acts as a frontend which
interacts with users and other OTcl objects. It may defines its own procedures and variables
to facilitate the interaction. Note that the member procedures and variables in the OTcl

NAME: SRINIVAS B REG NO:113022104147


domain are called instance procedures (instprocs) and instance variables (instvars),
respectively

NS2 provides a large number of built-in C++ objects. It is advisable to use these C++
objects to set up a simulation using a Tcl simulation script. However, advance users may find
these objects insufficient. They need to develop their own C++ objects, and use a OTcl
configuration interface to put together these objects. After simulation, NS2 outputs either
text-based or animation-based simulation results. To interpret these results graphically and
interactively, tools such as NAM (Network AniMator) and XGraph are used. To analyze a
particular behaviour of the network, users can extract a relevant subset of text-based data and
transform it to a more conceivable presentation

Tcl scripting:
• Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage

Basics of TCL

Syntax: command arg1 arg2 arg3


Hello World!
puts stdout{Hello, World!} Hello, World!

Variables

Command Substitution
set a 5 set len [string length foobar]
set b $a set len [expr [string length foobar] + 9]

Wired TCL Script Components


Create the event scheduler
Open new files & turn on the tracing
Create the nodes Setup the links Configure the traffic type (e.g., TCP, UDP, etc)
Set the time of traffic generation (e.g., CBR, FTP)
Terminate the simulation

NS2 Simulator Preliminaries.

1. Initialization and termination aspects of the ns simulator.


2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables

Initialization and Termination of TCL Script in NS-2

An ns simulation starts with the command


set ns [new Simulator]

NAME: SRINIVAS B REG NO:113022104147


Which is thus the first line in the tcl script. This line declares a new variable as using
the set command, you can call this variable as you wish, In general people declares it as ns
because it is an instance of the Simulator class, so an object the code[new Simulator] is
indeed the installation of the class Simulator using the reserved word new.

In order to have output files with data on the simulation (trace files) or files used for
visualization (nam files), we need to create the files using ―open command:

#Open the Trace file

set tracefile1 [open out.tr w]


$ns trace-all $tracefile1
#Open the NAM trace file

set namfile [open out.nam w]


$ns namtrace-all $namfile

The above creates a dta trace file called out.tr and a nam visualization trace file called
out.nam. Within the tcl script, these files are not called explicitly by their names, but instead
by pointers that are declared above and called ―tracefile1 and ―namfile respectively.
Remark that they begins with a # symbol. The second line open the file ―out.tr to be used for
writing, declared with the letter ―w. The third line uses a simulator method called trace-all
that have as parameter the name of the file where the traces will go.

Define a “finish‟ procedure

Proc finish { } {
global ns tracefile1 namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
}

Definition of a network of links and nodes

The way to define a node is

set n0 [$ns node]

Once we define several nodes, we can define the links that connect them. An example of a
definition of a link is:
$ns duplex-link $n0 $n2 10Mb 10ms DropTail

Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of
propagation delay and a capacity of 10Mb per sec for each direction.

To define a directional link instead of a bi-directional one, we should replace ―duplex-link


by ―simplex-link. In ns, an output queue of a node is implemented as a part of each link

NAME: SRINIVAS B REG NO:113022104147


whose input is that node. We should also define the buffer capacity of the queue related to
each link. An example would be:

#set Queue Size of link (n0-n2) to 20


$ns queue-limit $n0 $n2 20

FTP over TCP

TCP is a dynamic reliable congestion control protocol. It uses Acknowledgements created by


the destination to know whether packets are well received.
There are number variants of the TCP protocol, such as Tahoe, Reno, NewReno, Vegas. The
type of agent appears in the first line:

set tcp [new Agent/TCP]

The command $ns attach-agent $n0 $tcp defines the source node of the tcp connection.

The command set sink [new Agent /TCPSink]Defines the behavior of the destination node
of TCP and assigns to it a pointer called sink.

#Setup a UDP connection

set udp [new Agent/UDP]


$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_2

#setup a CBR over UDP connection

The below shows the definition of a CBR application using a UDP agent

The command $ns attach-agent $n4 $sink defines the destination node. The command $ns
connect $tcp $sink finally makes the TCP connection between the source and destination
nodes.

set cbr [new Application/Traffic/CBR]


$cbr attach-agent $udp
$cbr set packetsize_ 100
$cbr set rate_ 0.01Mb
$cbr set random_ false

TCP has many parameters with initial fixed defaults values that can be changed if mentioned
explicitly. For example, the default TCP packet size has a size of 1000bytes.This can be
changed to another value, say 552bytes, using the command $tcp set packetSize_ 552.

When we have several flows, we may wish to distinguish them so that we can identify them
with different colors in the visualization part. This is done by the command $tcp set fid_ 1

NAME: SRINIVAS B REG NO:113022104147


that assigns to the TCP connection a flow identification of ―1.We shall later give the flow
identification of ―2‖ to the UDP connection.

Simulation of congestion control using sliding window protocol

Sliding.tcl

# sliding window mechanism with some features


# such as labeling, annotation, nam-graph, and window size monitoring
set ns [new Simulator]
set n0 [$ns node]
set n1 [$ns node]
$ns at 0.0 "$n0 label Sender"
$ns at 0.0 "$n1 label Receiver"
set nf [open sliding.nam w]
$ns namtrace-all $nf
set f [open sliding.tr w]
$ns trace-all $f
$ns duplex-link $n0 $n1 0.2Mb 200ms DropTail
$ns duplex-link-op $n0 $n1 orient right
$ns queue-limit $n0 $n1 10
Agent/TCP set nam_tracevar_ true
set tcp [new Agent/TCP]
$tcp set windowInit_ 4
$tcp set maxcwnd_ 4
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns add-agent-trace $tcp tcp
$ns monitor-agent-trace $tcp
$tcp tracevar cwnd_
$ns at 0.1 "$ftp start"
$ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink"
$ns at 3.5 "finish"
$ns at 0.0 "$ns trace-annotate \"Sliding Window with window size 4 (normal operation)\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\""
$ns at 0.11 "$ns trace-annotate \"Send Packet_0,1,2,3\""
$ns at 0.34 "$ns trace-annotate \"Receive Ack_0,1,2,3\""
$ns at 0.56 "$ns trace-annotate \"Send Packet_4,5,6,7\""
$ns at 0.79 "$ns trace-annotate \"Receive Ack_4,5,6,7\""
$ns at 0.99 "$ns trace-annotate \"Send Packet_8,9,10,11\""
$ns at 1.23 "$ns trace-annotate \"Receive Ack_8,9,10,11 \""
$ns at 1.43 "$ns trace-annotate \"Send Packet_12,13,14,15\""
$ns at 1.67 "$ns trace-annotate \"Receive Ack_12,13,14,15\""
$ns at 1.88 "$ns trace-annotate \"Send Packet_16,17,18,19\""

NAME: SRINIVAS B REG NO:113022104147


$ns at 2.11 "$ns trace-annotate \"Receive Ack_16,17,18,19\""
$ns at 2.32 "$ns trace-annotate \"Send Packet_20,21,22,23\""
$ns at 2.56 "$ns trace-annotate \"Receive Ack_24,25,26,27\""
$ns at 2.76 "$ns trace-annotate \"Send Packet_28,29,30,31\""
$ns at 3.00 "$ns trace-annotate \"Receive Ack_28\""
$ns at 3.1 "$ns trace-annotate \"FTP stops\""

proc finish {} {
global ns
$ns flush-trace
# close $nf
puts "running nam..."
exec nam sliding.nam &
exit 0
}
$ns run

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Result:
Thus, we have Studied Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.

NAME: SRINIVAS B REG NO:113022104147


Ex.No: 8 Study of TCP/UDP performance using the Simulation tool.

Date: 25.09.24

AIM:
To simulate the performance of TCP/UDP using NS2.

Algorithm
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation

PROGRAM:
wired.tcl

#create a simulator object


set ns [new Simulator]

#create a trace file, this file is for logging purpose


set tracefile [open wired.tr w]
$ns trace-all $tracefile

#create a animation infomration or NAM file creation


set namfile [open wired.nam w]
$ns namtrace-all $namfile

#create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

#creation of link between nodes with DropTail Queue


#Droptail means Dropping the tail.
$ns duplex-link $n0 $n1 5Mb 2ms DropTail
$ns duplex-link $n2 $n1 10Mb 5ms DropTail
$ns duplex-link $n1 $n4 3Mb 10ms DropTail
$ns duplex-link $n4 $n3 100Mb 2ms DropTail
$ns duplex-link $n4 $n5 4Mb 10ms DropTail

NAME: SRINIVAS B REG NO:113022104147


#creation of Agents
#node 0 to Node 3
set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $n0 $udp
$ns attach-agent $n3 $null
$ns connect $udp $null

#creation of TCP Agent


set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $tcp
$ns attach-agent $n5 $sink
$ns connect $tcp $sink

#creation of Application CBR, FTP


#CBR - Constant Bit Rate (Example nmp3 files that have a CBR or 192kbps, 320kbps, etc.)
#FTP - File Transfer Protocol (Ex: To download a file from a network)
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp

set ftp [new Application/FTP]


$ftp attach-agent $tcp

#Start the traffic


$ns at 1.0 "$cbr start"
$ns at 2.0 "$ftp start"

$ns at 10.0 "finish"

#the following procedure will be called at 10.0 seconds


proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
puts "running nam..."
exec nam wired.nam &
exit 0
}

puts "Simulation is starting..."


$ns run

NAME: SRINIVAS B REG NO:113022104147


OUTPUT:

wired.tr

NAME: SRINIVAS B REG NO:113022104147


RESULT:

The simulation of the performance of TCP/UDP using NS2.

NAME: SRINIVAS B REG NO:113022104147


Ex.No:9 Simulation of Distance Vector/ Link State Routing algorithm.

Date: 03.10.24
AIM:
To simulate and study the Distance Vector routing algorithm using simulation.

SOFTWARE REQUIRED:
NS-2

THEORY:
Distance Vector Routing is one of the routing algorithm in a Wide Area Network for
computing shortest path between source and destination. The Router is one main devices used
in a wide area network. The main task of the router is Routing. It forms the routing table and
delivers the packets depending upon the routes in the table-either directly or via an
intermediate devices.
Each router initially has information about all its neighbours. Then this information will be
shared among nodes.

ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose distance vector routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.

PROGRAM:

set ns [new Simulator]


set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }

NAME: SRINIVAS B REG NO:113022104147


$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail

$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail


$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

NAME: SRINIVAS B REG NO:113022104147


OUTPUT:

RESULT:
Thus the Distance vector Routing Algorithm was Simulated and studied.

NAME: SRINIVAS B REG NO:113022104147


Ex.No:10 Simulation of Link Routing algorithm.

Date: 03.10.24

AIM:
To simulate and study the link state routing algorithm using simulation.

SOFTWARE REQUIRED:
NS-2

THEORY:
In link state routing, each router shares its knowledge of its neighborhood with every other
router in the internet work. (i) Knowledge about Neighborhood: Instead of sending its
entire routing table a router sends info about its neighborhood only. (ii) To all Routers: each
router sends this information to every other router on the internet work not just to its neighbor
.It does so by a process called flooding. (iii)Information sharing when there is a change:
Each router sends out information about the neighbors when there is change.

PROCEDURE:
The Dijkstra algorithm follows four steps to discover what is called the shortest path
tree(routing table) for each router:The algorithm begins to build the tree by identifying its
roots. The root router’s trees the router itself. The algorithm then attaches all nodes that can
be reached from the root. The algorithm compares the tree’s temporary arcs and identifies the
arc with the lowest cumulative cost. This arc and the node to which it connects are now a
permanent part of the shortest path tree. The algorithm examines the database and identifies
every node that can be reached from its chosen node. These nodes and their arcs are added
temporarily to the tree.
The last two steps are repeated until every node in the network has become a permanent part
of the tree.

ALGORITHM:
1. Create a simulator object
2. Define different colors for different data flows
3. Open a nam trace file and define finish procedure then close the trace file, and execute nam
on trace file.
4. Create n number of nodes using for loop
5. Create duplex links between the nodes
6. Setup UDP Connection between n(0) and n(5)
7. Setup another UDP connection between n(1) and n(5)
8. Apply CBR Traffic over both UDP connections
9. Choose Link state routing protocol to transmit data from sender to receiver.
10. Schedule events and run the program.

PROGRAM:
set ns [new Simulator]

NAME: SRINIVAS B REG NO:113022104147


set nr [open thro.tr w]
$ns trace-all $nr
set nf [open thro.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exec nam thro.nam &
exit 0
}

for { set i 0 } { $i < 12} { incr i 1 } {


set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail

set udp0 [new Agent/UDP]


$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red

NAME: SRINIVAS B REG NO:113022104147


$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

OUTPUT:

RESULT:
Thus the simulation for Link state routing was done usingNS2.

NAME: SRINIVAS B REG NO:113022104147


Ex.No:11 Performance Evaluation of Routing Protocols using Simulation tool.

Date: 14.10.24

A) UNICAST PROTOCOL

AIM:
To write a ns2 program for implementing unicast routing protocol.

ALGORITHM:

1. Start the program.


2. Declare the global variables ns for creating a new simulator.
3. Set the color for packets.
4. Open the network animator file in the name of file2 in the write mode.
5. Open the trace file in the name of file 1 in the write mode.
6. Set the unicast routing protocol to transfer the packets in network.
7. Create the required no of nodes.
8. Create the duplex-link between the nodes including the delay time,bandwidth and
dropping queue mechanism.
9. Give the position for the links between the nodes.
10. Set a tcp reno connection for source node.
11. Set the destination node using tcp sink.
12. Setup a ftp connection over the tcp connection.
13. Down the connection between any nodes at a particular time.
14. Reconnect the downed connection at a particular time.
15. Define the finish procedure.
16. In the definition of the finish procedure declare the global variables ns, file1, and file2.
17. Close the trace file and name file and execute the network animation file.
18. At the particular time call the finish procedure.
19. Stop the program.

PROGRAM:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace file
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {}
{
global ns file1 file2

NAME: SRINIVAS B REG NO:113022104147


$ns flush-trace
close $file1
close $file2
exec nam out.nam &

exit 3
}
# Next line should be commented out to have the static routing
$ns rtproto DV
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n4 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n2 0.3Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n4 0.3Mb 10ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 0.5Mb 10ms DropTail

#Give node position (for NAM)


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n1 $n4 orient up-left
$ns duplex-link-op $n3 $n5 orient left-up
$ns duplex-link-op $n4 $n5 orient right-up

#Setup a TCP connection


set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns rtmodel-at 1.0 down $n1 $n4

$ns rtmodel-at 4.5 up $n1 $n4


$ns at 0.1 "$ftp start"
$ns at 6.0 "finish"
$ns run

NAME: SRINIVAS B REG NO:113022104147


OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


Ex.No : 11(b) MULTICASTING ROUTING PROTOCOL
Date: 14.10.24

AIM:
To write a ns2 program for implementing multicasting routing protocol.

ALGORITHM:
1. Start the program.
2. Declare the global variables ns for creating a new simulator.
3. Set the color for packets.
4. Open the network animator file in the name of file2 in the write mode.
5. Open the trace file in the name of file 1 in the write mode.
6. Set the multicast routing protocol to transfer the packets in network.
7. Create the multicast capable no of nodes.
8. Create the duplex-link between the nodes including the delay time,bandwidth and
dropping queue mechanism.
9. Give the position for the links between the nodes.
10. Set a udp connection for source node.
11. Set the destination node ,port and random false for the source and destination files.
12. Setup a traffic generator CBR for the source and destination files.
13. Down the connection between any nodes at a particular time.
14. Create the receive agent for joining and leaving if the nodes in the group.
15. Define the finish procedure.
16. In the definition of the finish procedure declare the global variables.
17. Close the trace file and namefile and execute the network animation file.
18. At the particular time call the finish procedure.
19. Stop the program.

PROGRAM:
# Create scheduler
#Create an event scheduler wit multicast turned on
set ns [new Simulator -multicast on]
#$ns multicast
#Turn on Tracing
set tf [open output.tr w]
$ns trace-all $tf
# Turn on nam Tracing
set fd [open mcast.nam w]
$ns namtrace-all $fd
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]

NAME: SRINIVAS B REG NO:113022104147


# Create links
$ns duplex-link $n0 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail
$ns duplex-link $n3 $n7 1.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 1.5Mb 10ms DropTail
$ns duplex-link $n4 $n6 1.5Mb 10ms DropTail
# Routing protocol: say distance vector
#Protocols: CtrMcast, DM, ST, BST
set mproto DM
set mrthandle [$ns mrtproto $mproto {}]
# Allocate group addresses
set group1 [Node allocaddr]
set group2 [Node allocaddr]
# UDP Transport agent for the traffic source
set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0


$udp0 set dst_addr_ $group1
$udp0 set dst_port_ 0
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp0
# Transport agent for the traffic source
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
$udp1 set dst_addr_ $group2
$udp1 set dst_port_ 0
set cbr2 [new Application/Traffic/CBR]
$cbr2 attach-agent $udp1
# Create receiver
set rcvr1 [new Agent/Null]
$ns attach-agent $n5 $rcvr1
$ns at 1.0 "$n5 join-group $rcvr1 $group1"
set rcvr2 [new Agent/Null]
$ns attach-agent $n6 $rcvr2
$ns at 1.5 "$n6 join-group $rcvr2 $group1"
set rcvr3 [new Agent/Null]
$ns attach-agent $n7 $rcvr3
$ns at 2.0 "$n7 join-group $rcvr3 $group1"
set rcvr4 [new Agent/Null]
$ns attach-agent $n5 $rcvr1
$ns at 2.5 "$n5 join-group $rcvr4 $group2"
set rcvr5 [new Agent/Null]
$ns attach-agent $n6 $rcvr2
$ns at 3.0 "$n6 join-group $rcvr5 $group2"
set rcvr6 [new Agent/Null]
$ns attach-agent $n7 $rcvr3
$ns at 3.5 "$n7 join-group $rcvr6 $group2"
$ns at 4.0 "$n5 leave-group $rcvr1 $group1"

NAME: SRINIVAS B REG NO:113022104147


$ns at 4.5 "$n6 leave-group $rcvr2 $group1"
$ns at 5.0 "$n7 leave-group $rcvr3 $group1"
$ns at 5.5 "$n5 leave-group $rcvr4 $group2"
$ns at 6.0 "$n6 leave-group $rcvr5 $group2"
$ns at 6.5 "$n7 leave-group $rcvr6 $group2"
# Schedule events

$ns at 0.5 "$cbr1 start"


$ns at 9.5 "$cbr1 stop"
$ns at 0.5 "$cbr2 start"
$ns at 9.5 "$cbr2 stop"
#post-processing
$ns at 10.0 "finish"
proc finish {}
{
global ns tf
$ns flush-trace
close $tf
exec nam mcast.nam &
exit 0
}
# For nam
#Colors for packets from two mcast groups
$ns color 10 red
$ns color 11 green
$ns color 30 purple
$ns color 31 green
# Manual layout: order of the link is significant!
#$ns duplex-link-op $n0 $n1 orient right
#$ns duplex-link-op $n0 $n2 orient right-up
#$ns duplex-link-op $n0 $n3 orient right-down
# Show queue on simplex link n0->n1
#$ns duplex-link-op $n2 $n3 queuePos 0.5
# Group 0 source
$udp0 set fid_ 10
$n0 color red
$n0 label "Source 1"
# Group 1 source
$udp1 set fid_ 11
$n1 color green
$n1 label "Source 2"
$n5 label "Receiver 1"
$n5 color blue
$n6 label "Receiver 2"
$n6 color blue
$n7 label "Receiver 3"
$n7 color blue
#$n2 add-mark m0 red
#$n2 delete-mark m0"
# Animation rate

NAME: SRINIVAS B REG NO:113022104147


$ns set-animation-rate 3.0ms
$ns run

OUTPUT:

RESULT:
Thus the case study about the different routing algorithms to select the network path with
its optimum and economical during data transfer is done.

NAME: SRINIVAS B REG NO:113022104147


Ex.No:12 (a) Simulation of Error Detection Code (like CRC)
Date: 14.10.24

AIM:
To implement error-checking code using Java.

ALGORITHM:
1. Start the Program
2. Given a bit string, append 0S to the end of it (the number of 0s is the same as the degree
of the generator polynomial) let B(x) be the polynomial corresponding to B.
3. Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine
the remainder R(x). This division is to be done using Modulo 2 Division.
4. Define T(x) = B(x) –R(x)
5. (T(x)/G(x) => remainder 0)
6. Transmit T, the bit string corresponding to T(x).
7. Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial. The
receiver divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T = T’
and no error occurred otherwise, the receiver concludes an error occurred and requires a
retransmission
8. Stop the Program

PROGRAM:
import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;
System.out.println("Enter number of data bits : "); data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine()); divisor=new int[divisor_bits];
System.out.println("Enter Divisor bits : ");
for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());
System.out.print("Data bits are : ");
for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();
System.out.print("divisor bits are : ");

NAME: SRINIVAS B REG NO:113022104147


for(int i=0; i< divisor_bits; i++)
System.out.print(divisor[i]);
System.out.println();
*/
tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
/*------------------ CRC GENERATION-----------------------*/
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : "); for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++){
rem[j] = div[j];
}
rem=divide(div, divisor, rem);
for(int i=0;i<div.length;i++)
{
//append dividend and remainder
crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/*-------------------ERROR DETECTION---------------------*/
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits : "); for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());
System.out.print("crc bits are : ");
for(int i=0; i< crc.length; i++)
System.out.print(crc[i]);
System.out.println();
for(int j=0; j<crc.length; j++){
rem[j] = crc[j];
}
rem=divide(crc, divisor, rem);
for(int i=0; i< rem.length; i++)
{
if(rem[i]!=0)
{
System.out.println("Error");
break;
}
if(i==rem.length-1)
System.out.println("No Error");
}

NAME: SRINIVAS B REG NO:113022104147


System.out.println("THANK YOU.... :)");
}
static int[] divide(int div[],int divisor[], int rem[])
{
int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
while(rem[cur]==0 && cur!=rem.length-1)
cur++;
if((rem.length-cur)<divisor.length)
break;}return rem;}

OUTPUT :
Enter number of data bits :
7
Enter data bits :
1
0
1
1
0
0
1
Enter number of bits in divisor :
3
Enter Divisor bits :
1
0
1
Dividend (after appending 0's) are : 101100100
CRC code :
101100111
Enter CRC code of 9 bits :
1
0
1

1
0
0
1
0
1
crc bits are : 101100101
Error
THANK YOU.... :)
BUILD SUCCESSFUL (total time: 1 minute 34 seconds)

RESULT:

NAME: SRINIVAS B REG NO:113022104147


Thus the above program for error-checking code use was executed successfully

TOPIC BEYOND SYLLABUS

Ex.no.12 b. Simulation of Go Back N protocol


Date: 14.10.24

AIM:
To Simulate and to study of Go Back N protocol

ALGORITHM :

1. The source node transmits the frames continuously.


2. Each frame in the buffer has a sequence number starting from 1 and increasing up to the
window size.
3. The source node has a window i.e. a buffer to store the frames. This buffer size is the
number of frames to be transmitted continuously.

4. The size of the window depends on the protocol designer.


5. For the first frame, the receiving node forms a positive acknowledgement if the frame is
received without error.
6. If subsequent frames are received without error (up to window size) cumulative positive
acknowledgement is formed.
7. If the subsequent frame is received with error, the cumulative acknowledgment error-free
frames are transmitted. If in the same window two frames or more frames are received
with error, the second and the subsequent error frames are neglected. Similarly even the
frames received without error after the receipt of a frame with error are neglected.
8. The source node retransmits all frames of window from the first error frame.
9. If the frames are errorless in the next transmission and if the acknowledgment is error
free, the window slides by the number of error-free frames being transmitted.
10. If the acknowledgment is transmitted with error, all the frames of window at source are
retransmitted, and window doesn’t slide.
11. This concept of repeating the transmission from the first error frame in the window is
called as GOBACKN transmission flow control protocol.

PROGRAM :
#send packets one by one
set ns [new Simulator] set n0 [$ns node]
set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] $n0
color "purple" $n1 color "purple" $n2 color "violet" $n3 color "violet" $n4 color "chocolate"
$n5
color "chocolate" $n0 shape box ;
$n1 shape box ; $n2 shape box ; $n3 shape box ; $n4 shape box ; $n5 shape box ;
$ns at 0.0 "$n0 label SYS0"
$ns at 0.0 "$n1 label SYS1"
$ns at 0.0 "$n2 label SYS2"
$ns at 0.0 "$n3 label SYS3"
$ns at 0.0 "$n4 label SYS4"
$ns at 0.0 "$n5 label SYS5"
set nf [open goback.nam w] $ns namtrace-all $nf
set f [open goback.tr w] $ns trace-all $f

NAME: SRINIVAS B REG NO:113022104147


$ns duplex-link $n0 $n2 1Mb 20ms DropTail $ns duplex-link-op $n0 $n2 orient right-down
$ns
queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1Mb 20ms DropTail $ns duplex-link-op $n1 $n2 orient right-up $ns
duplex-link $n2 $n3 1Mb 20ms DropTail $ns duplex-link-op $n2 $n3 orient right
$ns duplex-link $n3 $n4 1Mb 20ms DropTail $ns duplex-link-op $n3 $n4 orient right-up $ns
duplex-link $n3 $n5 1Mb 20ms DropTail $ns duplex-link-op $n3 $n5 orient right-down
Agent/TCP set_nam_tracevar_true
set tcp [new Agent/TCP] $tcp set fid 1
$ns attach-agent $n1 $tcp
set sink [new Agent/TCPSink] $ns attach-agent $n4 $sink $ns connect $tcp $sink
set ftp [new Application/FTP] $ftp attach-agent $tcp
$ns at 0.05 "$ftp start"
$ns at 0.06 "$tcp set windowlnit 6"
$ns at 0.06 "$tcp set maxcwnd 6"

$ns at 0.25 "$ns queue-limit $n3 $n4 0"


$ns at 0.26 "$ns queue-limit $n3 $n4 10"
$ns at 0.305 "$tcp set windowlnit 4"
$ns at 0.305 "$tcp set maxcwnd 4"
$ns at 0.368 "$ns detach-agent $n1 $tcp ; $ns detach-agent $n4 $sink"
$ns at 1.5 "finish"
$ns at 0.0 "$ns trace-annotate \"Goback N end\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""
$ns at 0.06 "$ns trace-annotate \"Send 6Packets from SYS1 to SYS4\""
$ns at 0.26 "$ns trace-annotate \"Error Occurs for 4th packet so not sent ack for the Packet\""
$ns at 0.30 "$ns trace-annotate \"Retransmit Packet_4 to 6\""
$ns at 1.0 "$ns trace-annotate \"FTP stops\""
proc finish {}
{
global ns nf
$ns flush-trace
close $nf
puts "filtering..."
#exec tclsh../bin/namfilter.tcl goback.nam
#puts "running nam..."
exec nam goback.nam &
exit 0
}
$ns run.

OUTPUT

NAME: SRINIVAS B REG NO:113022104147


RESULT:
Thus the Go back N and Selective Repeat protocols were Simulated and studied

NAME: SRINIVAS B REG NO:113022104147


Ex.no.12 c. CARRIER SENSE MULTIPLE ACCESS
Date: 14.10.24

AIM:
To write a ns2 program for implementing carrier sense multiple access.

ALGORITHM:
1. Start the program.
2. Declare the global variables ns for creating a new simulator.

3. Set the color for packets.


4. Open the network animator file in the write mode.
5. Open the trace file and the win file in the write mode.
6. Transfer the packets in network.
7. Create the capable no of nodes.
8. Create the duplex-link between the nodes including the delay time,bandwidth and
dropping queue mechanism.
9. Give the position for the links between the nodes.
10. Set a tcp connection for source node.
11. Set the destination node using tcp sink.
12. Set the window size and the packet size for the tcp.
13. Set up the ftp over the tcp connection.
14. Set the udp and tcp connection for the source and destination.
15. Create the traffic generator CBR for the source and destination files.
16. Define the plot window and finish procedure.
17. In the definition of the finish procedure declare the global variables.
18. Close the trace file and namefile and execute the network animation file.
19. At the particular time call the finish procedure.
20. Stop the program.

PROGRAM:
set ns [new Simulator]
$ns color 1 blue
$ns color 2 red
set fi1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $fi1
set fi2 [open out.nam w]
$ns namtrace-all $fi2
proc finish {}
{
global ns fi1 fi2
$ns flush-trace
close $fi1
close $fi2
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]

NAME: SRINIVAS B REG NO:113022104147


set n2 [$ns node]

set n3 [$ns node]


set n4 [$ns node]
set n5 [$ns node]
$n1 color red
$n1 shape box
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd
Channel]
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetsize_ 552
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 24.0 "$ftp stop"
$ns at 24.5 "$cbr stop"
proc plotwindow { tcpSource file }
{
global ns
set time 0.1

set now [$ns now]


set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotwindow $tcpSource $file"

NAME: SRINIVAS B REG NO:113022104147


}
$ns at 1.0 "plotwindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
$ns at 125.0 "finish"
$ns run

OUTPUT:

NAME: SRINIVAS B REG NO:113022104147


RESULT
Thus the carrier sense multiple access are implemented and executed successfully.

NAME: SRINIVAS B REG NO:113022104147

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy