0% found this document useful (0 votes)
50 views82 pages

Ilovepdf Merged

This document serves as a manual for a Computer Network Laboratory course, detailing the importance of computer networks, their design, and the use of Java for implementation. It outlines course objectives, outcomes, and evaluation methods, while also introducing NS2 as a simulation tool for networking research. Additionally, it describes the department's vision, mission, and educational objectives, emphasizing practical learning and ethical development in Computer Science and Engineering.

Uploaded by

gangambika
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)
50 views82 pages

Ilovepdf Merged

This document serves as a manual for a Computer Network Laboratory course, detailing the importance of computer networks, their design, and the use of Java for implementation. It outlines course objectives, outcomes, and evaluation methods, while also introducing NS2 as a simulation tool for networking research. Additionally, it describes the department's vision, mission, and educational objectives, emphasizing practical learning and ethical development in Computer Science and Engineering.

Uploaded by

gangambika
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/ 82

PREFACE

The rising importance of the computer systems to everyday life makes the role of the computer
networks vital. Computer networks are used to transfer data between the communicating systems.
Computer networks need to be designed using appropriate topology and network technologies in order
to be fast, reliable and easy expandable. The transmitted data is divided into the appropriate Protocol
Data Units. Ability to analyze the data is required to understand the network protocols and to
troubleshoot the network problems. Local Area Networks interconnect to one another and compose
Wide Area Networks. Routing is critical in WANs.

This manual for practical Computer Network Laboratory (21CS52) is an introduction to all popular
concepts in networking and their implementation with the Java language. It is planned for beginners who
would like to learn the subject through programs. Java programming language offers several facilities to
group data and methods together in convenient packages, or classes. With the emergence of Java as the
most popular language of implementation blossomed from Sun Microsystems. The introduction of
network Simulator-2 helps the students to simulate the designed network and gain knowledge on
network performance by using TCL scripting.

This edition emphasizes on abstract concepts of Networking and few of the algorithms and describes
how to simulate the designed network which is useful in problem solving using available packages and
utility from java packages and TCL scripts. Students will gain a good appreciation of the subject as this
manual has a clear display of syntax and elegant programming examples. To simplify concepts of NS2
and networking algorithm given are implemented in simple Java language understandable even by
beginners.
Department of Computer Science and Engineering
ABOUT
Department of Artificial Intelligence & Machine Learning was established in the year 2022. The
department has a very good infrastructure and faculty to provide excellent education to meet the
industry standards.

Today, the department caters to the needs of more than 200 UG students. It houses state of the art
computing facilities with high end servers which support the LAN, provide a Linux/Unix
environment, also provides exclusive library facility to its students and boasts of well trained and
experienced faculty teaching the departments various courses in the areas of Computer Networks,
Computer Architecture, Database Systems, Microprocessor, Operating Systems, Analysis and
Design of Algorithms and Software Engineering.
The department lays stress on the practical and application based aspects through laboratories,
seminars, group discussions, viva-voce and project work, keeping pace with the growth in
Computer Science & Engineering technology. The Students are given scope to conduct
experiments on innovative ideas. A sound theoretical and practical work prepares the students in
wider field of Computer Science & Engineering to take up challenging jobs in the area of:
System Software Development Application Software Development Computer Networking
Vision:
To be a Department of Excellence in Technical Education through Innovative Learning
Approach with Social Commitment in the field of Computer Science & Engineering.
Mission:
M1: To impart quality technical education that nurtures the young minds by providing the best
of teaching learning process and state of the art infrastructure.
M2: To foster technological advancement through research.
M3: To inculcate holistic personality development through best practices.
M4: To implant ethical and social commitment that grooms the students to become
responsible citizens.
Program Educational Objectives (PEOs)
PEO1: To achieve sustainable growth as Computer Science Engineers in reputed
organizations.

PEO2: To accomplish higher education and research with highest degree of professionalism
and integrity.

PEO3: To extend the services to mankind by exhibiting leadership qualities and ethical
values.

Program Specific Outcomes (PSOs)

PSO1 Apply the strong knowledge and principles of Computer Science and Engineering to
model and design various computing systems.
PSO2 Develop the diverse applications in well promised domains by adopting the practices
of Computer Science & Engineering.
PROGRAM OUTCOMES (POs)

PO’s DESCRIPTION
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, review 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.
EAST WEST INSTITUTE OF TECHNOLOGY
# 63 Off Magadi Main Road, Vishwaneedam Post, Bangalore-91

(Affiliated to VTU, Belagavi, Approved by AICTE, New Delhi & Recognized by Govt.
of Karnataka)

Department of COMPUTER SCIENCE and

engineering

Computer Network laboratory


(BCS502)
V Semester B.E
Prepared
by,

Prof. Gangambika G
COMPUTER NETWORK LABORATORY
(Effective from the academic year 2018 -2019)
SEMESTER – V
Course Code BCS502 CIE Marks 25
Number of Contact 3:0:2:0 SEE Marks 00
Hours/Week
Credits – 2

COURSE OBJECTIVES
This Course will enable the students:
 Study the TCP/IP protocol suite, switching criteria and Medium Access Control
protocols for reliable and noisy channels.
 Learn network layer services and IP versions.
 Discuss transport layer services and understand UDP and TCP protocols.
 Demonstrate the working of different concepts of networking layers and protocols.

COURSE OUTCOMES

 Explain the fundamentals of computer networks.


 Apply the concepts of computer networks to demonstrate the working of various
layers and protocols in communication network.
 Analyze the principles of protocol layering in modern communication systems.
 Demonstrate various Routing protocols and their services using tools such as Cisco
packet tracer.
CO- PO Mapping

COURSE
OUTCOME PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

CO1 2 0 0 0 1 1 1 1 0 0 0 1
CO2 3 1 0 0 1 1 1 1 0 0 0 1
CO3 3 2 0 0 1 1 2 1 0 0 0 1
CO4 3 2 0 0 1 1 1 1 0 0 0 1

PSO 1 2

CO1 1
CO2 2
CO3 2 1
CO4 2 1
LAB EVALUATION PROCESS

WEEK WISE EVALUATION OF EACH PROGRAM


PART A
SL.NO ACTIVITY MARKS

1 Observation Book 5

2 Record 5

TOTAL 10

INTERNAL ASSESSMENT
PART B
SL.NO ACTIVITY MARKS

1 Procedure 2.5

2 Conduction 10

3 Viva -Voce 2.5

TOTAL 15
PART A + PART B 25
COMPUTER NETWORK LABORATORY
(Effective from the academic year 2023 -2024)
SEMESTER – V
Course Code BCS502 CIE Marks 25
Number of Contact 3:0:2:0 SEE Marks 00
Hours/Week
Credits – 2

Sl. PROGRAMS
No.
Implement three nodes point – to – point network with duplex links between
1 them. Set the queue size, vary the bandwidth, and find the number of packets
dropped
Implement transmission of ping messages/trace route over a network
2 topology consisting of 6 nodes and find the number of packets dropped due
to congestion.
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and
3
plot congestion window for different source / destination..
4 Develop a program for error detecting code using CRC-CCITT (16- bits).
Develop a program to implement a sliding window protocol in the data link
5
layer
Develop a program to find the shortest path between vertices using the
6
Bellman-Ford and path vector routing algorithm.
Using TCP/IP sockets, write a client – server program to make the client
7 send the file name and to make the server send back the contents of the
requested file if present.
Develop a program on a datagram socket for client/server to display the
8 messages on client side, typed at the server side.
Develop a program for a simple RSA algorithm to encrypt and decrypt the
8 data.
Develop a program for congestion control using a leaky bucket algorithm.
10
Computer Network Laboratory BCS502

BasicsofNS2
NS2 is an open-source simulation tool that runs on Linux. It is a discreet event
simulator targeted at networking research and provides substantial support for simulation of
routing, multicast protocols and IP protocols, such as UDP, TCP, RTP and SRM over wired
and wireless (local and satellite)networks
 Widely known as NS2, is simply an event driven simulation tool.
 Useful in studying the dynamic nature of communication networks.
 Simulation of wired as well as 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.
BasicArchitectureofNS2

Fig1:ArchitectureofNS2

Simple Script Explanation

set ns[newSimulator]:generatesanNSsimulatorobjectinstance,andassignsitto variable ns. What


this line does is the following:

 Initialize the packet format(ignore this for now)


 Create a scheduler(default Is calendar scheduler)
 Select the default address format (ignore this for now)

The "Simulator" object has member functions that do the following:

 Create compound objects such as nodes and links(described later)


 Connect network component objects created(ex. attach-agent)

Dept. of CSE, EWIT Page1


Computer Network Laboratory BCS502

 Set network component parameters(mostly for compound objects)


 Create connections between agents(ex. make connection between a "tcp" and
"sink")
 Specify NAM display options , etc.

Comments: A Tcl comment line begins with #. More generally, any occurrence of the # sign
in a command line means that text to the right of it is considered as comment and is ignored.

Assignment and Interrogation of Variables: The command set is used to assign variables,
and a $ sign is used to obtain the value of a variable. All variables in Tcl are stored as strings.
set a 1
set b$a

Sets both variables a and b to the string "1".

Continuation lines: The backslash may be used to continue a Tcl command on another
line. For example,
seta\
b

$nscolorfid color: is to set color of the packets for a flow specified by the flow id (fid). This
member function of "Simulator" object is for the NAM display, and has no effect on the
actual simulation.

$nsnamtrace-allfile-descriptor: This member function tells the simulator to record


simulation traces in NAM input format. It also gives the file name that the trace will be
written to later by the command $nsflush-trace. Similarly, the member function trace-all is
for recording the simulation trace in a general format.

procfinish {}: is called after this simulation is over by the command $nsat 5.0 "finish". In
this function, post-simulation processes are specified.

set n0[$nsnode]: The member function node creates a node. A node in NS is compound
object made of address and port classifiers.

$nsduplex-linknode1 node2 bandwidth delay queue-type: creates two simplex links of


specified bandwidth and delay, and connects the two specified nodes. In NS, the output
queue of a node is implemented as a part of a link; therefore users should specify the queue-
type when creating links. The queue can be either of type Drop Tail or RED.

Dept. of CSE, EWIT Page2


Computer Network Laboratory BCS502

$nsqueue-limit node1 node2 number: This line sets the queue limit of the two simplex links
that connect node1 and node2 to the number specified.

settcp[newAgent/TCP]: This line shows how to create a TCP agent. But in general, users
can create any agent or traffic sources in this way. Agents and traffic sources are in factbasic
objects (not compound objects), mostly implemented in C++ and linked to OTcl. Therefore,
there are no specific Simulator object member functions that create these object instances.
To create agents or traffic sources, a user should know the class names these objects
(Agent/TCP, Agnet/TCP Sink, Application/FTP and so on.

$nsattach-agent node agent: The attach-agent member function attaches an agent object
created to a node object. Actually, what this function does is call the attach member function
of specified node, which attaches the given agent to itself. Therefore, a user can do the same
thing by, for example, $n0attach$tcp.Similarly, each agent object has a member function
attach-agent that attaches a traffic source object to itself

$nsconnect agent1 agent2: After two agents that will communicate with each other are
created, the next thing is to establish a logical network connection between them. This line
establishes a network connection by setting the destination address to each others' network
and port address pair.

$nsat time "string": This member function of a Simulator object makes the scheduler
(scheduler_ is the variable that points the scheduler object created by [new Scheduler]
command at the beginning of the script) to schedule the execution of the specified string at
given simulation time.

For example, $nsat 0.1"$cbr start" will make the scheduler call a start member function of
the CBR traffic source object, which starts the CBR to transmit data. In NS, usually a traffic
source does not transmit actual data, but it notifies the underlying agent that it has some
amount of data to transmit, and the agent, just knowing how much of the data to transfer,
creates packets and sends them.

For the application like tcp or udp to run, we need to set two agents and the application
which should run in between. When using tcp, we have ftp as the application and tcp sink as
the end agent. Connection must be made between tcp and tcp sink, same in udp with cbr and
null respectively.

Dept. of CSE, EWIT Page3


Computer Network Laboratory BCS502

Set tcp [new Agent/TCP]


$nsattach-agent$n0$tcp

This would make at cp agent and connect it with the node.

set ftp [newApplication/FTP]


$ftp attach-agent$tcp

Now the ftp is connected with the tcp

setagent [new Agent/TCPSink]

$nsattach-agent$n3$sink

Now the tcp sink is set to a node where the tcp packets are received.

The tcp and sink (agents)needs to be connected, such that the network flows.

$nsconnect$tcp$sink

Same for UDP

setudp [newAgent/UDP]
$nsattach-agent$n2$udp

setcbr[new Application/Traffic/CBR]
$cbrattach-agent$udp

setnull[new Agent/Null]
$nsattach-agent$n3$null

$nsconnect$udp $null

The file should be saved in .tcl format and should use ns filename.tcl to run

Dept. of CSE, EWIT Page4


Computer Network Laboratory BCS502

Ns2Tracefile format

$1
$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11
2
Pk
Fro To Pkt Pk
Even Tim t Flag Flo Srcadd Destadd Seqnu
m nod typ tid
t e siz s wid r r m
node e e e

 Event or type identifier


+: a packet enqueue event
-: a packet dequeue event
r: apacketreceptionevent
d: a packet drop event
c: apacketcollisionattheMAClevel
 Time: at which the packet tracing string is created.
 Source and destination node: source and destination ID’s of tracing objects
 Packet type : type of the packet such as, TCP,UDP, CBR,ACK, FTP etc.
 Packet size: size of packets in bytes.
 Flags:7digit string
“-“ :disable
1st: “E”-ECN (Explicit Congestion Notification)echo is enabled.
2nd: “P”-the priority in the IP header is enabled.
3rd: notinuse
4th:“A”-Congestion action.
5th:“E”-Congestion has occurred.
6th:“F”-the TCP fast start is used.
7th:“N”-Explicit Congestion Notification (ECN)is on.
 Flow id
 Source and destination address: The format of these two fields is “a.b”, where “a"
is the address and "b" is the port.
 Sequence number
 Packet unique ID

Dept. of CSE, EWIT Page5


Computer Network Laboratory BCS502

1. Implement three nodes point – to – point network with duplex links


between them. Set the queue size, vary the bandwidth and find the
number of packets dropped.

Topology Design:

Fig2:Topology of 3nodes point-to-point network.

Source code:

set ns [ new Simulator ]

set tf [ open lab1.tr w ]

$ns trace-all $tf

set nf [ open lab1.nam w ]

$ns namtrace-all $nf

# The below code is used to create the nodes.

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

Dept. of CSE, EWIT Page6


Computer Network Laboratory BCS502
#The below used to give color to the packets.

$ns color 1 "red"

$ns color 2 "blue"

$n0 label "Source/udp0"

$n1 label "Source/udp1"

$n2 label "Router"

$n3 label "Destination/Null"

#Vary the below Bandwidth and see the number of packets dropped.

$ns duplex-link $n0 $n2 10Mb 300ms DropTail

$ns duplex-link $n1 $n2 10Mb 300ms DropTail

$ns duplex-link $n2 $n3 1Mb 300ms DropTail

#The below code is used to set the queue size b/w the nodes

$ns set queue-limit $n0 $n2 10

$ns set queue-limit $n1 $n2 10

$ns set queue-limit $n2 $n3 5

#the below code is used to attach an UDP0 agent to n0, UDP1

#agent to n1 and null agent to n3.

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

set null3 [new Agent/Null]

$ns attach-agent $n3 $null3

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

#The below code sets the udp0 packets to red and udp1

Dept. of CSE, EWIT Page7


Computer Network Laboratory BCS502
#packets to blue color

$udp0 set class_ 1

$udp1 set class_ 2

#The below code is used to connect the agents.

$ns connect $udp0 $null3

$ns connect $udp1 $null3

#The below code is used to set the packet size to 500

$cbr1 set packetSize_ 500Mb

#The below code is used to set the interval of the packets,

#i.e., Data rate of the packets. if the data rate is high

#then packets drops are high.

$cbr1 set interval_ 0.005

proc finish { } {

global ns nf tf

$ns flush-trace

exec nam lab1.nam &

close $tf

close $nf

exit 0

$ns at 0.1 "$cbr0 start"

$ns at 0.1 "$cbr1 start"

$ns at 10.0 "finish"

$ns run

Dept. of CSE, EWIT Page8


Computer Network Laboratory BCS502

AWKScript:
BEGIN{
#include<stdio.h>
count=0;
}
{
if($1==”d”)
count++;
}END{
printf (“Total no.of packets dropped due to congestion is:%d”, count);
}

Torun:
ns lab1.tcl

awk–flab1.awklab1.tr

TheTotalnoofpacketsDroppedduetocongestion:750

Dept. of CSE, EWIT Page9


Computer Network Laboratory BCS502

Snapshot:

Fig3:The drop of packets at node2

Dept. of CSE, EWIT Page10


Computer Network Laboratory BCS502
2. Implement transmission of ping messages/trace route over a network
topology consisting of 6 nodes and find the number of packets
dropped due to congestion.

Topology Design:

Fig4:Topologyofnetworkwith6nodestodemonstratepingmessage transmission

Note:

1. Vary the bandwidth and queue size between the nodes n0-n2 , n2-n4. n6-n2 and n2-
n5and see the number of packets dropped at thenodes.

2. The ping agent can be attached to the nodes by giving


i. setping0[newAgent/Ping]
$nsattach-agent$n0 $ping0
ii. The ping agents can be connected using the syntax given below.
$nsconnect$ping0 $ping4

Dept. of CSE, EWIT Page11


Computer Network Laboratory BCS502
Sourcecode:
set ns [new Simulator]
set tf [open lab2.tr w]
$ns trace-all $tf
set nf [open lab2.nam w]
$ns namtrace-all $nf
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]
$n0 label "Ping0"
$n4 label "Ping4"
$n5 label "Ping5"
$n6 label "Ping6"
$n2 label "Router"
$ns color 1 "red"
$ns color 2 "green"
$ns duplex-link $n0 $n2 100Mb 300ms DropTail
$ns duplex-link $n2 $n6 1Mb 300ms DropTail
$ns duplex-link $n5 $n2 100Mb 300ms DropTail
$ns duplex-link $n2 $n4 1Mb 300ms DropTail
$ns duplex-link $n3 $n2 1Mb 300ms DropTail
$ns duplex-link $n1 $n2 1Mb 300ms DropTail
$ns queue-limit $n0 $n2 5
$ns queue-limit $n2 $n6 2
$ns queue-limit $n2 $n4 3
$ns queue-limit $n5 $n2 5
#The below code is used to connect between the ping agents to the node n0, n4 ,
n5 and n6.
set ping0 [new Agent/Ping]
$ns attach-agent $n0 $ping0
set ping4 [new Agent/Ping]
$ns attach-agent $n4 $ping4
set ping5 [new Agent/Ping]
$ns attach-agent $n5 $ping5
set ping6 [new Agent/Ping]
$ns attach-agent $n6 $ping6
Dept. of CSE, EWIT Page12
Computer Network Laboratory BCS502
$ping0 set packetSize_ 50000
$ping0 set interval_ 0.0001
$ping5 set packetSize_ 60000
$ping5 set interval_ 0.00001
$ping0 set class_ 1
$ping5 set class_ 2
$ns connect $ping0 $ping4
$ns connect $ping5 $ping6
#The below function is executed when the ping agent receives a reply from the
destination
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts " The node [$node_ id] received an reply from $from with round trip time of
$rtt"
}
proc finish {} {
global ns nf tf
exec nam lab2.nam &
$ns flush-trace
close $tf
close $nf
exit 0
}
#The below code makes the link down(failure) at 0.9 from n2 to n6 and when the
time becomes 1.5 the link between n2 to n6 is enabled.
$ns rtmodel-at 0.9 down $n2 $n6
$ns rtmodel-at 1.5 up $n2 $n6
$ns at 0.1 "$ping0 send"
$ns at 0.2 "$ping0 send"
$ns at 0.3 "$ping0 send"
$ns at 0.4 "$ping0 send"
$ns at 0.5 "$ping0 send"
$ns at 0.6 "$ping0 send"
$ns at 0.7 "$ping0 send"
$ns at 0.8 "$ping0 send"
$ns at 0.9 "$ping0 send"
$ns at 1.0 "$ping0 send"
$ns at 1.1 "$ping0 send"
$ns at 1.2 "$ping0 send"
$ns at 1.3 "$ping0 send"

Dept. of CSE, EWIT Page13


Computer Network Laboratory BCS502
$ns at 1.4 "$ping0 send"
$ns at 1.5 "$ping0 send"
$ns at 1.6 "$ping0 send"
$ns at 1.7 "$ping0 send"
$ns at 1.8 "$ping0 send"
$ns at 0.1 "$ping5 send"
$ns at 0.2 "$ping5 send"
$ns at 0.3 "$ping5 send"
$ns at 0.4 "$ping5 send"
$ns at 0.5 "$ping5 send"
$ns at 0.6 "$ping5 send"
$ns at 0.7 "$ping5 send"
$ns at 0.8 "$ping5 send"
$ns at 0.9 "$ping5 send"
$ns at 1.0 "$ping5 send"
$ns at 1.1 "$ping5 send"
$ns at 1.2 "$ping5 send"
$ns at 1.3 "$ping5 send"
$ns at 1.4 "$ping5 send"
$ns at 1.5 "$ping5 send"
$ns at 1.6 "$ping5 send"
$ns at 1.7 "$ping5 send"
$ns at 1.8 "$ping5 send"
$ns at 5.0 "finish"
$ns run

AWKScript:
BEGIN{
#include<stdio.h>
count=0;
}
{
if($1=="d")
count++;
} END {
printf("Total no. of packets dropped due to congestion is:%d\n",count);
}

Dept. of CSE, EWIT Page14


Computer Network Laboratory BCS502
Torun:

nsping.tcl
awk–f ping.awk ping.tr
Total no. of packets dropped due to congestion is:20

Snapshot:

Fig5: Thepinging ofthenodes.

Fig6:RTT taken to receive ping messages between nodes.

Dept. of CSE, EWIT Page15


Computer Network Laboratory BCS502
3. Implement an Ethernet LAN using n nodes and set multiple
traffic nodes and plot congestion window for different source
/destination.

Topology Design:

Fig7: TopologyofEthernetLANnetworkwith4 nodes.

Note:
The congestion at the nodes can be traced by the following steps:
Step1:Createafile1.trandfile2.tr set
file1 [open file1.trw] set
file2 [open file2.trw]
Step 2: Attach these files(file1.tr&file2.tr)to the agents
tcp0 and tcp1 as shown below.
$tcp0attach$file1
$tcp1attach $file2

Step 3: To trace the congestion window value we use the trace


command to trace the congestion window values.
$tcp0tracecwnd_
$tcp1tracecwnd_
Then, the congestion window values are stored in the file1
and file2.
Step 4:Toplot the graph the steps are given below
nslab7.tcl
awk -f lab7.awk file1.tr>tcp1
awk –flab7.awk file2.tr>tcp2

Dept. of CSE, EWIT Page16


Computer Network Laboratory BCS502
Sourcecode:

set ns [new Simulator]


set tf [open lab3.tr w]
$ns trace-all $tf
set nf [open lab3.nam w]
$ns namtrace-all $nf
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns color 1 "red"
$ns color 2 "blue"
#create LAN
$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
#Attach Agents
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp0 $sink3
set tcp2 [new Agent/TCP]
$ns attach-agent $n2 $tcp2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
set sink1 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns connect $tcp2 $sink1
$tcp0 set class_ 1
$tcp2 set class_ 2
######To trace the congestion window##########
set file1 [open file1.tr w]
$tcp0 attach $file1
$tcp0 trace cwnd_
$tcp0 set maxcwnd_ 10
set file2 [open file2.tr w]
$tcp2 attach $file2
$tcp2 trace cwnd_
proc finish { } {
global nf tf ns
$ns flush-trace
Dept. of CSE, EWIT Page17
Computer Network Laboratory BCS502
exec nam lab3.nam &
close $nf
close $tf exit 0
}
$ns at 0.1 "$ftp0 start"
$ns at 1.5 "$ftp0 stop"
$ns at 2 "$ftp0 start"
$ns at 3 "$ftp0 stop"
$ns at 0.2 "$ftp2 start"
$ns at 2 "$ftp2 stop"
$ns at 2.5 "$ftp2 start"
$ns at 4 "$ftp2 stop"
$ns at 5.0 "finish"
$ns run

AWK file

BEGIN{

#include<stdio.h>

if($6=="cwnd_")

printf("%f \t %f \n", $1,$7);

END{

puts "DONE"

Torun:

nslan.tcl
awk–flan.awkfile1.tr>tcp0
awk–flan.awkfile2.tr>tcp1
xgraph –x“time” –y“congestion value”tcp0tcp1

Dept. of CSE, EWIT Page18


ComputerNetwork Laboratory BCS502
Snapshot:

Fig8:Traffic flow through LAN

Fig9:The congestion window graph

Dept. of CSE, EWIT Page19


Computer Network Laboratory BCS502

4. Write a program for error detecting code using CRC-CCITT (16-bits).


The cyclic redundancy check (CRC) is a technique used to detect errors in digital data.
CRC is a hash function that detects accidental changes to raw computer data commonly used in
digital telecommunications networks and storage devices such as hard disk drives. This
technique was invented by W. Wesley Peterson in 1961 and further developed by the CCITT
(International Telegraph and Telephone Consultative Committee). Cyclic redundancy checks are
quite simple to implement in hardware and can be easily analyzed mathematically. It is one of
the better techniques in detecting common transmission errors.

As explained above cyclic redundancy check is also applied to storage devices like hard
disks. In this case, check bits are allocated to each block in the hard disk. When a corrupt or
incomplete file is read by the computer, the cyclic redundancy error is reported. This could be
from another storage device or from CD/DVDs. The common reasons for errors include system
crashes, incomplete or corrupt files, or files with lots of bugs.

Fig 16: Block diagram of CRC.

Dept. of CSE, EWIT Page20


Computer Network Laboratory BCS502
Steps:
 First, a string ofn-1 0sisappendedtothe data unit.

 Thenumberof0sisonelessthanthenumberofbitsinthedivisor which is n bits.

 Then the newly elongated data unit is divided by the divisor using a process called binary
division (XOR).

 TheremainderisCRC.TheCRCreplacestheappended0sattheend of the data unit.

 The data unit arrives at the receiver first, followed by the CRC.

 The receiver treats whole string as the data unit and divides it by the same divisor that was
used to find the CRC remainder.

 If the remainder is 0 then the data unit is error free. Otherwise it having some error and it
must be discarded.

Source code:

//Computer Network Lab Error detection code using CRC-CCITT


import java.util.Scanner;
import java.io.*;
public class CRC1 {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

//Input Data Stream


System.out.print("Enter message bits: ");
String message = sc.nextLine();
System.out.print("Enter generator: ");
String generator = sc.nextLine();
int data[] = new int[message.length() + generator.length() - 1];
int divisor[] = new int[generator.length()];
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");

//Calculation of CRC
for(int i=0;i<message.length();i++)
{
if(data[i]==1)
Dept. of CSE, EWIT Page21
Computer Network Laboratory BCS502
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}

//Display CRC
System.out.print("The checksum code is: ");
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<data.length;i++)
System.out.print(data[i]);
System.out.println();

//Check for input CRC code


System.out.print("Enter checksum code: ");
message = sc.nextLine();
System.out.print("Enter generator: ");
generator = sc.nextLine();
data = new int[message.length() + generator.length() - 1];
divisor = new int[generator.length()];
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");

//Calculation of remainder
for(int i=0;i<message.length();i++) {
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}

//Display validity of data


boolean valid = true;
for(int i=0;i<data.length;i++)
if(data[i]==1){
valid = false;
break;
}

if(valid==true)
System.out.println("Data stream is valid");
else
System.out.println("Data stream is invalid. CRC error occurred.");
}

Dept. of CSE, EWIT Page22


Computer Network Laboratory BCS502
Snapshot:

Fig 17:Output of CRC 16bits.

Dept. of CSE, EWIT Page23


Computer Network Laboratory BCS502

5. Develop a program to implement a sliding window protocol in the data


link layer

The sliding window protocol is a well-known technique that plays a significant role in ensuring
reliable and orderly data exchange between a sender and a receiver. In this section, we will delve
into the concept of the sliding window protocol and demonstrate how to implement it using Java.

Understanding the Sliding Window Protocol


The sliding window protocol is a communication protocol used to manage the flow control and
reliability of data transmission over a network. It allows the sender to transmit a specified
number of packets, known as the window size, without waiting for an acknowledgment from the
receiver for each packet. This approach enhances efficiency by minimizing the communication
overhead.
The protocol employs two primary components: the sender's sliding window and the receiver's
sliding window. The sender's window keeps track of the packets that have been sent but not yet
acknowledged, while the receiver's window tracks the expected sequence of packets to receive.
As acknowledgments are received, both windows slide forward, allowing for the continuous
flow of data.

Implementation of the Sliding Window Protocol


To implement the sliding window protocol in Java, we will create a simplified example of a
sender and a receiver using sockets for communication. We will assume a reliable connection, so
the focus will be on the sliding window mechanism.

Source Code:
package dev;

import java.util.Random;
import java.util.Scanner;

public class Transmission {

public static void transmission(long i, long N, long tf, long[] tt) {


while (i <= tf) {
Dept. of CSE, EWIT Page24
Computer Network Laboratory BCS502
int z = 0;
for (long k = i; k < i + N && k <= tf; k++) {
System.out.println("Sending Frame " + k + "...");
tt[0]++;
}
for (long k = i; k < i + N && k <= tf; k++) {
int f = new Random().nextInt(2);
if (f == 0) {
System.out.println("Acknowledgment for Frame " + k + "...");
z++;
} else {
System.out.println("Timeout!! Frame Number : " + k + " Not Received");
System.out.println("Retransmitting Window...");
break;
}
}
System.out.println();
i += z;
}
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.print("Enter the Total number of frames: ");
long tf = scanner.nextLong();
System.out.print("Enter the Window Size: ");
long N = scanner.nextLong();

long i = 1;
long[] tt = {0}; // Using an array to allow passing by reference
transmission(i, N, tf, tt);

System.out.println("Total number of frames which were sent and resent are: " + tt[0]);

scanner.close();
}
}

OUTPUT 1:
Enter the window size: 3
Enter the total number of frames: 5
Starting Sliding Window Protocol Simulation
Sending frame: 0
Sending frame: 1
Sending frame: 2
Frame 0 lost, waiting for retransmission
Frame 1 lost, waiting for retransmission
Frame 2 lost, waiting for retransmission
Sending frame: 0
Sending frame: 1
Dept. of CSE, EWIT Page25
Computer Network Laboratory BCS502
Sending frame: 2
Received ACK for frame: 0
Received ACK for frame: 1
Frame 2 lost, waiting for retransmission
Sending frame: 2
Sending frame: 3
Sending frame: 4
Frame 2 lost, waiting for retransmission
Frame 3 lost, waiting for retransmission
Received ACK for frame: 4
Sending frame: 2
Sending frame: 3
Sending frame: 4
Received ACK for frame: 2
Received ACK for frame: 3
Frame 4 lost, waiting for retransmission
Simulation complete
OUTPUT 2:
Enter the window size: 3
Enter the total number of frames: 5
Starting Sliding Window Protocol Simulation
Sending frame: 0
Sending frame: 1
Sending frame: 2
Received ACK for frame: 0
Frame 1 lost, waiting for retransmission
Frame 2 lost, waiting for retransmission
Sending frame: 1
Sending frame: 2
Sending frame: 3
Received ACK for frame: 1
Received ACK for frame: 2
Frame 3 lost, waiting for retransmission
Sending frame: 3
Sending frame: 4
Received ACK for frame: 3
Received ACK for frame: 4
Simulation complete

Dept. of CSE, EWIT Page26


ComputerNetwork Laboratory BCS502

6. Write a program to find the shortest path between vertices using


bellman- ford algorithm.

Algorithm

Steps:

Input : Graph and a source vertex src .

Output: Shortest distance to all vertices from src. If there is a negative weight cycle, then shortest
distances are not calculated, negative weight cycle is reported.

1. This step initializes distances from source to all vertices as in finite and distance to source
itself as 0. Create an array dist[] of size |V| with all values as infinite except dist[src] where src is
source vertex.

2. This step calculates shortest distances. Do following |V|-1 times where |V| is the number of
vertices in given graph.

a) Do following for each edge u-v.

If dist[v]>dist[u]+weigh to f edge uv, then update list[v].

dist[v] = dist[u] + weight of edge uv

3. Thisstepreportsifthereisanegativeweightcycleingraph.Dofollowingfor each edge u-v.

If dist[v] >dist[u] + weight of edge uv, then

“Graph contains negative weight cycle”.

The idea of step 3 is, step 2 guarantees shortest distances if graph doesn’t contain
negative weight cycle. If we iterate through all edges one more time and get a shorter path for
any vertex, then there is a negative weight cycle.

Dept. of CSE, EWIT Page27


Computer Network Laboratory BCS502

Source Code:

import java.util.Scanner;
public class ford
{
private int D[];
private int num_ver;
public static final int MAX_VALUE = 999;
public ford(int num_ver)
{
this.num_ver = num_ver;
D = new int[num_ver + 1];
}

public void BellmanFordEvaluation(int source, int A[][])


{
for (int node = 1; node <= num_ver; node++)
{
D[node] = MAX_VALUE;
}

D[source] = 0;

for (int node = 1; node <= num_ver - 1; node++)


{
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
D[dn] = D[sn] + A[sn][dn];
}
}
}
}

for (int sn = 1; sn <= num_ver; sn++)


{
for (int dn = 1; dn <= num_ver; dn++)
{
Dept. of CSE, EWIT Page28
Computer Network Laboratory BCS502
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
System.out.println("The Graph contains negative egde cycle"); }
}
}

for (int vertex = 1; vertex <= num_ver; vertex++)


{
System.out.println("distance of source"+source+"to"+vertex+"is" + D[vertex]);
}
}

public static void main(String[ ] args)


{
int num_ver = 0;
int source;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of vertices");
num_ver = scanner.nextInt();

int A[][] = new int[num_ver + 1][num_ver + 1];


System.out.println("Enter the adjacency matrix");
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
A[sn][dn] = scanner.nextInt();
if (sn == dn)
{
A[sn][dn] = 0;
continue;
}
if (A[sn][dn] == 0)
{
A[sn][dn] = MAX_VALUE;
}
}
}

Dept. of CSE, EWIT Page29


Computer Network Laboratory BCS502

System.out.println("Enter the source vertex");


source = scanner.nextInt();
ford b = new ford (num_ver);
b.BellmanFordEvaluation(source, A);
scanner.close();
}

Fig18: Example directed graph

Dept. of CSE, EWIT Page30


Computer Network Laboratory BCS502

Snapshot:

Fig 19:Output of Bellman Ford algorithm

Dept. of CSE, EWIT Page31


Computer Network Laboratory BCS502

7. Using TCP/IP sockets, write a client – server program to make the client
send the file name and to make the server send back the contents of the
requested file if present.

Fig20:TCP client/server communication flow.

Dept. of CSE, EWIT Page32


Computer Network Laboratory BCS502

Methods and description

 Public Server Socket(int port)throws IOException: Attempts to create a server

socket bound to the specified port. An exception occurs if the port is already
bound by another application.

 public Socket accept() throws IOException: Waits for an incoming client. This

method blocks until either a client connects to the server on the specified port or
the socket times out, assuming that the time-out value has been set using the set
So Timeout() method. Otherwise, this method blocks indefinitely. 

 public Socket(Inet Address host, int port) throws IOException: This method
attempts to connect to the specified server at the specified port. If this constructor
does not throw an exception, the connection is successful and the client is
connected to the server. 

 Public Inet Address get Inet Address(): This method returns the address of the
other computer that this socket is connected to. 

 Public int getPort():Returns the port the socket is bound to on there mote machine.

 Public InputStreamgetInputStream() throws IOException: Returns the input


stream of the socket. The input stream is connected to the output stream of the
remote socket. 

 Public OutputStreamgetOutputStream() throws IOException: Returns the


output stream of the socket. The output stream is connected to the input stream of
the remote socket.

Dept. of CSE, EWIT Page33


Computer Network Laboratory BCS502

// TCP Server
import java.net.*;
import java.io.*;
public class TCPS
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock=new ServerSocket(4000);
System.out.println("Server ready for connection");
Socket sock=sersock.accept();
System.out.println("Connection Is successful and waiting for chatting");
InputStream istream=sock.getInputStream();
BufferedReader fileRead=new BufferedReader(new InputStreamReader(istream));
String fname=fileRead.readLine();
BufferedReader ContentRead=new BufferedReader(new FileReader(fname));
OutputStream ostream=sock.getOutputStream();
PrintWriter pwrite=new PrintWriter(ostream,true);
String str;
while((str=ContentRead.readLine())!=null){
pwrite.println(str);
}
sock.close();
sersock.close();
pwrite.close();
fileRead.close();
ContentRead.close();
}
}

//TCP Client
import java.net.*;
import java.io.*;
public class TCPC
{
public static void main(String[] args) throws Exception
{
Socket sock=new Socket("127.0.01",4000);
System.out.println("Enter the filename");
BufferedReader keyRead=new BufferedReader(new InputStreamReader(System.in));
String fname=keyRead.readLine();
OutputStream ostream=sock.getOutputStream();
PrintWriter pwrite=new PrintWriter(ostream,true);
pwrite.println(fname);
InputStream istream=sock.getInputStream();
BufferedReader socketRead=new BufferedReader(new InputStreamReader(istream));
String str;
while((str=socketRead.readLine())!=null)
{
System.out.println(str);

Dept. of CSE, EWIT Page34


Computer Network Laboratory BCS502
}
pwrite.close();
socketRead.close();
keyRead.close();
}
}
Snapshot:

Fig 21: TCP server

Fig 22: TCPclient.

Dept. of CSE, EWIT Page35


Computer Network Laboratory BCS502

8. Write a program on datagram socket for client/server to display the


messages on client side, typed at the server side.

Fig23:UDP client/server communication flow.

Methods and description

 DatagramSocket(intport) throws SocketEeption: it creates a datagram socket


and binds it with the given Port Number. 
 DatagramPacket(byte[]buffer,intlength): it creates a datagram packet. This
constructor is used to receive the packets. 

Dept. of CSE, EWIT Page36


Computer Network Laboratory BCS502

 DatagramPacket(byte[] buffer, int length, InetAddress address, int port):it


creates a datagram packet. This constructor is used to send the packets. 

UDP Server Source code:


import java.io.*;
importjava.net.*;
importjava.util.*;
public class udps
{
publicstaticvoid main(String[]args)
{
DatagramSocketskt=null;
Scannersc=newScanner(System.in); try
{
skt=newDatagramSocket(2400);
byte[] buffer=new byte[1000];
while(true)
{
DatagramPacketrequest=newDatagramPacket(buffer,buffer.length);
skt.receive(request);
Stringmessage=sc.nextLine();
byte[]sendMsg=message.getBytes();
DatagramPacket reply=new
DatagramPacket(sendMsg,sendMsg.length,request.getAddress(),request.getPort());
skt.send(reply);
}
}
catch(Exceptionex)
{
}
}
}

Dept. of CSE, EWIT Page37


Computer Network Laboratory BCS502

UDP Client Source code:

import java.io.*;
importjava.net.*;
publicclassudpc
{
publicstaticvoid main(String[]args)
{
DatagramSocketskt;
try
{
skt=new DatagramSocket();
Stringmsg="textmessage";
byte[]b=msg.getBytes();
InetAddresshost=InetAddress.getByName("127.0.0.1");
intserverSocket=2400;
DatagramPacketrequest=newDatagramPacket(b,b.length,host,serverSocket);
skt.send(request);
byte[]buffer=newbyte[1000];
DatagramPacketreply=newDatagramPacket(buffer,buffer.length);
skt.receive(reply);
System.out.println("clientrecieved:"+newString(reply.getData()));
skt.close();
}
catch(Exceptionex){}
}
}

Dept. of CSE, EWIT Page38


Computer Network Laboratory BCS502

Snapshot:

Fig 24: UDP server

Fig 25: UDP client

Dept. of CSE, EWIT Page39


Computer Network Laboratory BCS502

9. Write a program for simple RSA algorithm to encrypt and decrypt the data.
RSA is an algorithm used by modern computers to encrypt and decrypt messages. It is an
asymmetric cryptographic algorithm. Asymmetric means that there are two different keys (one is
public key and another is private key). This is also called public key cryptography, because one
of the m can be given to everyone. The other key must be kept private. It is based on the fact that
finding the factors of an integer is hard (the factoring problem). RSA stands for Ron Rivest, Adi
Shamir and Leonard Adleman, who first publicly described it in 1978.
Following are the steps of RSA algorithm.

Key Generation
1. Generate two large prime numbers p and q, such that p!=q.
2. Let n=p*q.
3. Let t=(p-1)*(q-1)
4. Choose a small numbere ,co-prime tot, with
GCD(t,e)=1and 1<e<t.
5. Find d, such that d*emodt=1.
Publish e and n as public key.
Keep d and t as secret key.

Encryption

Cipher=(Message)emodn

Decryption

Message=(Cipher)dmodn

Dept. of CSE, EWIT Page40


Computer Network Laboratory BCS502

Source code:
importjava.util.Scanner;
public class RSA
{
publicstaticintp,q,n,t,flag,msg,m,temp;
public staticint e[]=new int[100]; public
staticint d[]=new int[100]; public static
int prime( intpr)
{
inti;

Doublea=(Math.sqrt(pr));
m=a.intValue();

for(i=2;i<=m;i++)
{
if(pr%i==0)
return0;
}

return1;

publicstaticvoidce()
{
intk=0;

for(inti=2;i<t;i++)
{
if(t%i==0)
continue;

flag=prime(i);

if(flag==1&&i!=p&&i!=q)
{

e[k]=i;
flag=cd(e[k]);

if(flag>0)
{
d[k]=flag;
k++;
}

Dept. of CSE, EWIT Page41


Computer Network Laboratory BCS502

if(k==99)
break;
}
}
}

publicstaticintcd( intx)
{
intk=1;

while(true)
{
k=k+t;

if(k%x==0)
return(k/x);
}

publicstaticvoid encrypt()
{

intpt,ct,key=e[0],k;

pt=msg;
k=1;

for(intj=0;j<key;j++)
{

k=k*pt;

k=k%n;
}

ct=k;
temp=ct;
System.out.println("\nTHEENCRYPTEDMESSAGEIS:"+ct);

publicstaticvoid decrypt()
{
intpt,ct,key=d[0],k;
ct=temp;
k=1;

Dept. of CSE, EWIT Page42


Computer Network Laboratory BCS502

for(intj=0;j<key;j++)
{
k=k*ct;
k=k%n;
}

pt=k;

System.out.println("\nTHEDECRYPTEDMESSAGEIS:"+pt);
}

publicstaticvoidmain(Stringargs[])
{
Scanner sc=new Scanner(System.in);
System.out.println("ENTERFIRSTPRIMENUMBER");
p=sc.nextInt();
flag=prime(p);
if(flag==0)
{
System.out.println("WRONGINPUT");
System.exit(1);
}

System.out.println("ENTERANOTHERPRIMENUMBER");
q=sc.nextInt();
flag=prime(q);
if(flag==0||p==q)
{
System.out.println("WRONGINPUT");
System.exit(1);
}

System.out.println("ENTERMESSAGE");
msg=sc.nextInt();
n=p*q;
t=(p-1)*(q-1);

ce();

System.out.println("POSSIBLEVALUESOFeANDdARE"); for
(int i=0;i< m-1;i++)
System.out.printf("\n%d\t%d",e[i],d[i]);

encrypt();
decrypt();
}
}

Dept. of CSE, EWIT Page43


Computer Network Laboratory BCS502

Snapshot:

Fig26:Simple RSA encryption and decryption.

Dept. of CSE, EWIT Page44


Computer Network Laboratory BCS502

10. Write a program for congestion control using leaky bucket algorithm.
To understand this concept first we have to know little about traffic shaping.
Traffic Shaping: This is a mechanism to control the amount and the rate of the traffic sent to the
network.
Two techniques can shape traffic:
1. Leaky Bucket
2. Token Bucket.
Suppose we have a bucket in which we are pouring water in a random order but we have to get
water in a fixed rate, for this we will make a hole at the bottom of the bucket. It will ensure that
watercomingoutisinsomefixedrate.Andalsoifbucketisfullwewillstoppouringinit. The input rate
can vary, but the output rate remains constant. Similarly, in networking, a technique called leaky
bucket can smooth out bursty traffic. Bursty chunks are stored in the bucket and sent out at an
average rate.

Fig27:Leakybucketscenario

In the above figure, we assume that the network has committed a bandwidth of 3 Mbps for a
host. The use of the leaky bucket shapes the input traffic to make it conform tot his commitment.
In Figure the host sends a burst of data at a rate of 12 Mbps for 2 s, for a total of 24 M bits of
data. The host is silent for 5 s and then sends data at a rate of 2 Mbps for 3 s, for a total of 6 M
bits of data. In all, the host has sent 30 M bits of data in 10 s. The leaky bucket smoothes the
traffic by sending out data at a rate of 3Mbps during the same10s.Without the leaky bucket, the

Dept. of CSE, EWIT Page45


Computer Network Laboratory BCS502
beginning burst may have hurt the network by consuming more bandwidth than is set aside for
this host. We can also see that the leaky bucket may prevent congestion.
Source code:

importjava.util.Random;
importjava.util.Scanner;
public class Leaky
{
publicstaticintbsize=0,packet,tgen,j=1;
public static String stop;
publicstatic final intbmax=1024;
public static final int orate=100;
publicstaticfinalintdelay=1500;
publicstaticRandomr=newRandom();
publicstaticRandomt=newRandom();
public class generating extends Thread
{
publicvoidrun()
{
while(stop==null)
{
tgen=t.nextInt(3000);
packet=r.nextInt(512);
if(bsize+packet<bmax)
{
bsize=bsize+packet;
System.out.printf("%13d%10d%15d%20d\n",j++,packet,bsize,bmax-bsize);
}
else
System.out.println("BucketOverFlow,"+packet+"sizeofpacketdiscarded");
try{Thread.sleep(tgen);}catch(Exception e){};
}
}
}
publicclassleakingextendsThread
{
publicvoidrun()
{
while(true)
{
if(bsize>0&&bsize-orate>0)//outputpacketrateis100bytes

Dept. of CSE, EWIT Page46


Computer Network Laboratory BCS502
{
bsize=bsize-orate;
System.out.printf("%38d%20d%15d\n",bsize,(bmax-bsize),orate);
}
else
{
System.out.printf("%38d%20d%15d\n",0,bmax,bsize);
bsize=0;
if(stop!=null)
return;}
try{Thread.sleep(delay);}catch(Exceptione){};
}
}
}
//@SuppressWarnings("resource")
publicstaticvoidmain(String[]args)
{
Leakyle=new Leaky();
Scannerin=newScanner(System.in);
generating g=le.new generating();
leaking l=le.new leaking();
System.out.println("Started");
System.out.println("OutputRateis:"+orate+"\nAnditisflowingatinterval:"+
((float)delay/1000)+"sec");
System.out.println("Enter anykeytostop input");
System.out.printf("Packetnumber|InputPacket|Bucketfilled|Remainingspace|Output rate");
System.out.println();
g.start();
try{Thread.sleep(10);}catch(Exceptione){};
l.start();
stop=in.next();
}
}

Dept. of CSE, EWIT Page47


Computer Network Laboratory BCS502

Snapshot:

Fig28: Congestion control using Leaky bucket algorithm.

Dept. of CSE, EWIT Page48


Computer Network Laboratory BCS502

EXPERIMENTS BEYOND THE CURRICULUM


1. Simulate a four node point –to- point network with links connected as follows:
n0-n2, n1-n2 and n2-n3. Apply TCP agents between n0-n3 and UDP agents between
n1-n3. Apply relevant applications over TCP and UDP agents changing the
parameter and determines the number of packets sent by TCP/UDP.

Design:

Note:
a. Calculate the total number of packets sent by tcp and udp by changing the
bandwidth from 100Mb,25Mb or 200mb in the topology and the data rate from
0.1,
0.001 as shown below.

Eg:
Bandwidth Data Rate TCP pkt sent UDP pkt sent
100Mb 0.1 2000 2500
200Mb 0.001 3400 6700

Dept. of CSE, EWIT Page49


Computer Network Laboratory BCS502

set ns [new Simulator] set tf [open


lab2.tr w]
$ns trace-all $tf
set nf [open lab2.nam w]
$ns namtrace-all $nf

set n0 [$ns node] set n1


[$ns node] set n2 [$ns
node] set n3 [$ns node]

# The below code is used to set the color and name's to the
#nodes.
$ns color 1 "red"
$ns color 2 "blue"
$n0 label "source/TCP"
$n1 label "source/UDP"
$n2 label "Router"
$n3 label "destination"

$ns duplex-link $n0 $n2 100Mb 1ms DropTail


$ns duplex-link $n1 $n2 100Mb 1ms DropTail
$ns duplex-link $n2 $n3 100Mb 1ms DropTail

# The below code is used to set the color and labels to the
#links.
$ns duplex-link-op $n0 $n2 color "green"
$ns duplex-link-op $n0 $n2 label "from 0-2"
$ns duplex-link-op $n1 $n2 color "green"
$ns duplex-link-op $n1 $n2 label "from 1-2"
$ns duplex-link-op $n2 $n3 color "green"
$ns duplex-link-op $n2 $n3 label "from 2-3"

Dept. of CSE, EWIT Page50


Computer Network Laboratory BCS502

# The below code is used create TCP and UDP agents and the
# traffic ftp & cbr respectively.
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0 set ftp0 [new
Application/FTP]
$ftp0 attach-agent $tcp0
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3

set udp1 [new Agent/UDP]


$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1 set null3
[new Agent/Null]
$ns attach-agent $n3 $null3

#The below code is used to set the packet size of ftp and
#udp.
$ftp0 set packetSize_ 500
$ftp0 set interval_ 0.001

#The below code is used to increase the data rate(if the


#interval is more then the more number of packets goes to
#destination).

$cbr1 set packetSize_ 500


$cbr1 set interval_ 0.001

#This code is used give a color red->tcp and blue ->udp.


$tcp0 set class_ 1
$udp1 set class_ 2

# The below code is used connect the agents.


$ns connect $tcp0 $sink3
$ns connect $udp1 $null3

Dept. of CSE, EWIT Page51


Computer Network Laboratory BCS502

proc finish { } {
global ns nf tf
$ns flush-trace exec nam
lab2.nam & close $nf
close $tf exit
0
}
$ns at 0.1 "$cbr1 start"
$ns at 0.2 "$ftp0 start"
$ns at 5.0 "finish"
$ns run
AWK Script:
BEGIN{
#include<stdio.h> tcp=0;
udp=0;

}
{
if($1=="r"&&$3=="2"&&$4=="3"&& $5=="tcp")
tcp++;
if($1=="r"&&$3=="2"&&$4=="3"&&$5=="cbr")
udp++;
}
END
{

Dept. of CSE, EWIT Page52


Computer Network Laboratory BCS502
printf("\n Total number of packets sent by TCP : %d\n",tcp); printf("\n Total number of packets
sent by UDP : %d\n",udp);
}
Output: ns lab2.tcl
awk –f lab2.awk lab2.tr
Total number of packets sent by TCP : 1200 Total number of
packets sent by UDP : 4500
Snapshot:

Dept. of CSE, EWIT Page53


Computer Network Laboratory BCS502
2. Simulate an Ethernet LAN using n nodes (6-10), change the error rate and data rate and
compare the throughput.
Design:

Note:
1. The lan can be created by using the command:
$ns make-lan “ $n0 $n1 $n2 $n3 ” 100Mb 10ms LL Queue/DropTail Mac/802_3

2. The Error between the nodes n3 and n6 can be added as follows: Set
err [ new ErrorModel ]
$ns lossmodel $err $n3 $n6
$err set rate_ 0.1 # used to set error rate.
3. The throughput can analyzed by changing the datarate and errorrate as shown below.
i. First, Fix the data rate to 0.0001 and vary the error rate then
throughput decreases as shown below.
Eg:
Error rate Data rate Throughput
0.1 0.0001 78Mbps
0.2 0.0001 68Mbps
0.3 0.0001 58Mbps
0.4 0.0001 48Mbps

i. Now Fix the error rate to 0.1 and vary the data rate then throughput
increases as shown below.
Error rate Data rate Throughput
0.1 0.1 78Mbps

Dept. of CSE, EWIT Page54


Computer Network Laboratory BCS502
0.2 0.01 89Mbps
0.1 0.001 100Mbps
0.1 0.0001 148Mbps

Program
set ns [new Simulator] set tf [open lab5.tr
w]
$ns trace-all $tf
set nf [open lab5.nam w]
$ns namtrace-all $nf

$ns color 1 "red"

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]

$n1 label "Source/UDP"


$n3 label "Error Node"
$n5 label "Destination"

#The below code is used to create a two Lans (Lan1 and


#Lan2).

$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
$ns make-lan "$n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3
#The below code is used to connect node n3 of lan1 and n6 of
#lan2.
$ns duplex-link $n3 $n6 100Mb 10ms DropTail

set udp1 [new Agent/UDP]


$ns attach-agent $n1 $udp1

set cbr1 [ new Application/Traffic/CBR]


Dept. of CSE, EWIT Page55
Computer Network Laboratory BCS502
$cbr1 attach-agent $udp1 set null5 [new
Agent/Null]
$ns attach-agent $n5 $null5

$ns connect $udp1 $null5

$cbr1 set packetSize_ 1000


$cbr1 set interval_ 0.0001 ;# This is the data rate. Change
;# this to increase the rate.

$udp1 set class_ 1


# The below code is used to add an error model between the
#nodes n3 and n6.
set err [new ErrorModel]
$ns lossmodel $err $n3 $n6
$err set rate_ 0.2 ;# This is the error rate. Change this
;#rate to add errors between n3 and n6.
proc finish { } {
global nf ns tf exec nam lab5.nam &
close $nf
close $tf exit 0
}
$ns at 5.0 "finish"
$ns at 0.1 "$cbr1 start"
$ns run
AWK Script: BEGIN{
#include <stdio.h> pkt=0;
time=0
}
{
if($1="r" && $3=="8" && $4=="5")
{
pkt=pkt+$6
time=$2
}
}
END
{
printf(" Throughput: %fMbps\n\n",(pkt/time)*(8/1000000));
}
Dept. of CSE, EWIT Page56
Computer Network Laboratory BCS502
Output: ns lab5.tcl
awk –f lab5.awk lab5.tr
Throughput:148Mbps
SnapShot:
Fig 4: The packet drop due to error at the node n3.

Dept. of CSE, EWIT Page57


Computer Network Laboratory BCS502

3. Program to implement Hamming Error Correction Code in Java


import java.util.*;
class Hamming {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of bits for the Hamming data:");
int n = scan.nextInt();
int a[] = new int[n];
for(int i=0 ; i < n ; i++) {
System.out.println("Enter bit no. " + (n-i) + ":");
a[n-i-1] = scan.nextInt();
}
System.out.println("You entered:");
for(int i=0 ; i < n ; i++) {
System.out.print(a[n-i-1]);
}
System.out.println();
int b[] = generateCode(a);
System.out.println("Generated code is:");
for(int i=0 ; i < b.length ; i++) {
System.out.print(b[b.length-i-1]);
}
System.out.println();
// Difference in the sizes of original and new array will give us the number of parity
bits added.
System.out.println("Enter position of a bit to alter to check for error detection at the
receiver end (0 for no error):");
int error = scan.nextInt();
if(error != 0) {
b[error-1] = (b[error-1]+1)%2;
}
System.out.println("Sent code is:");
for(int i=0 ; i < b.length ; i++) {
System.out.print(b[b.length-i-1]);
}
System.out.println();
receive(b, b.length - a.length);
}
static int[] generateCode(int a[]) {
// We will return the array 'b'.
int b[];
// We find the number of parity bits required:
int i=0, parity_count=0 ,j=0, k=0;
while(i < a.length) {
// 2^(parity bits) must equal the current position
// Current position is (number of bits traversed + number of parity bits + 1).
// +1 is needed since array indices start from 0 whereas we need to start from
1.
Dept. of CSE, EWIT Page58
Computer Network Laboratory BCS502

if(Math.pow(2,parity_count) == i+parity_count + 1) {
parity_count++;
}
else {
i++;
}
}

// Length of 'b' is length of original data (a) + number of parity bits.


b = new int[a.length + parity_count];

// Initialize this array with '2' to indicate an 'unset' value in parity bit locations:

for(i=1 ; i <= b.length ; i++) {


if(Math.pow(2, j) == i) {
// Found a parity bit location.
// Adjusting with (-1) to account for array indices starting from 0 instead of 1.

b[i-1] = 2;
j++;
}
else {
b[k+j] = a[k++];
}
}
for(i=0 ; i < parity_count ; i++) {
// Setting even parity bits at parity bit locations:

b[((int) Math.pow(2, i))-1] = getParity(b, i);


}
return b;
}

static int getParity(int b[], int power) {


int parity = 0;
for(int i=0 ; i < b.length ; i++) {
if(b[i] != 2) {
// If 'i' doesn't contain an unset value,
// We will save that index value in k, increase it by 1,
// Then we convert it into binary:

int k = i+1;
String s = Integer.toBinaryString(k);

//Nw if the bit at the 2^(power) location of the binary value of index is
1
//Then we need to check the value stored at that location.
//Checking if that value is 1 or 0, we will calculate the parity value.

Dept. of CSE, EWIT Page59


Computer Network Laboratory BCS502

int x = ((Integer.parseInt(s))/((int) Math.pow(10, power)))%10;


if(x == 1) {
if(b[i] == 1) {
parity = (parity+1)%2;
}
}
}
}
return parity;
}

static void receive(int a[], int parity_count) {


// This is the receiver code. It receives a Hamming code in array 'a'.
// We also require the number of parity bits added to the original data.
// Now it must detect the error and correct it, if any.

int power;
// We shall use the value stored in 'power' to find the correct bits to check for parity.

int parity[] = new int[parity_count];


// 'parity' array will store the values of the parity checks.

String syndrome = new String();


// 'syndrome' string will be used to store the integer value of error location.

for(power=0 ; power < parity_count ; power++) {


// We need to check the parities, the same no of times as the no of parity bits added.

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


// Extracting the bit from 2^(power):

int k = i+1;
String s = Integer.toBinaryString(k);
int bit = ((Integer.parseInt(s))/((int) Math.pow(10, power)))%10;
if(bit == 1) {
if(a[i] == 1) {
parity[power] = (parity[power]+1)%2;
}
}
}
syndrome = parity[power] + syndrome;
}
// This gives us the parity check equation values.
// Using these values, we will now check if there is a single bit error and then correct
it.

int error_location = Integer.parseInt(syndrome, 2);


if(error_location != 0) {

Dept. of CSE, EWIT Page60


Computer Network Laboratory BCS502
System.out.println("Error is at location " + error_location + ".");
a[error_location-1] = (a[error_location-1]+1)%2;
System.out.println("Corrected code is:");
for(int i=0 ; i < a.length ; i++) {
System.out.print(a[a.length-i-1]);
}
System.out.println();
}
else {
System.out.println("There is no error in the received data.");
}

// Finally, we shall extract the original data from the received (and corrected) code:
System.out.println("Original data sent was:");
power = parity_count-1;
for(int i=a.length ; i > 0 ; i--) {
if(Math.pow(2, power) != i) {
System.out.print(a[i-1]);
}
else {
power--;
}
}
System.out.println();
}
}

Dept. of CSE, EWIT Page61


Computer Network Laboratory BCS502
OUTPUT

Dept. of CSE, EWIT Page62


Computer Network Laboratory BCS502
QUESTION AND ANSWER
1) What is a Link?
A link refers to the connectivity between two devices. It includes the type of cables and protocols
used in order for one device to be able to communicate with the other.
2) What are the layers of the OSI reference model?
There are 7 OSI layers: Physical Layer, Data Link Layer, Network Layer, Transport Layer, Session
Layer, Presentation Layer and Application Layer.
3) What is backbone network?
A backbone network is a centralized infrastructure that is designed to distribute different routes and
data to various networks. It also handles management of bandwidth and various channels.
4) What is a LAN?
LAN is short for Local Area Network. It refers to the connection between computers and other
network devices that are located within a small physical location.
5) What is a node?
A node refers to a point or joint where a connection takes place. It can be computer or device that is
part of a network. Two or more nodes are needed in order to form a network connection.
6) What are routers?
Routers can connect two or more network segments. These are intelligent network devices that store
information in its routing table such as paths, hops and bottlenecks. With this info, they are able to
determine the best path for data transfer. Routers operate at the OSI Network Layer.
7) What is point to point link?
It refers to a direct connection between two computers on a network. A point to point connection
does not need any other network devices other than connecting a cable to the NIC cards of both
computers.
8) What is anonymous FTP?
Anonymous FTP is a way of granting user access to files in public servers. Users that are allowed
access to data in these servers do not need to identify themselves, but instead log in as an anonymous
guest.
9) What is subnet mask?
A subnet mask is combined with an IP address in order to identify two parts: the extended network
address and the host address. Like an IP address, a subnet mask is made up of 32 bits.
10) What is the maximum length allowed for a UTP cable?
A single segment of UTP cable has an allowable length of 90 to 100 meters. This limitation can be
overcome by using repeaters and switches.
11) What is data encapsulation?
Data encapsulation is the process of breaking down information into smaller manageable chunks
before it is transmitted across the network. It is also in this process that the source and destination
addresses are attached into the headers, along with parity checks.
12) Describe Network Topology
Network Topology refers to the layout of a computer network. It shows how devices and cables are
physically laid out, as well as how they connect to one another.
13) What is VPN?

Dept. of CSE, EWIT Page63


Computer Network Laboratory BCS502
VPN means Virtual Private Network, a technology that allows a secure tunnel to be created across a
network such as the Internet. For example, VPNs allow you to establish a secure dialup connection
to a remote server.
14) Briefly describe NAT.
NAT is Network Address Translation. This is a protocol that provides a way for multiple computers
on a common network to share single connection to the Internet.
15) What is the job of the Network Layer under the OSI reference model?
The Network layer is responsible for data routing, packet switching and control of network
congestion. Routers operate under this layer.
16) How does a network topology affect your decision in setting up a network?
Network topology dictates what media you must use to interconnect devices. It also serves as basis
on what materials, connector and terminations that is applicable for the setup.
17) What is RIP?
RIP, short for Routing Information Protocol is used by routers to send data from one network to
another. It efficiently manages routing data by broadcasting its routing table to all other routers
within the network. It determines the network distance in units of hops.
18) What are different ways of securing a computer network?
There are several ways to do this. Install reliable and updated anti-virus program on all computers.
Make sure firewalls are setup and configured properly. User authentication will also help a lot. All of
these combined would make a highly secured network.
19) What is NIC?
NIC is short for Network Interface Card. This is a peripheral card that is attached to a PC in order to
connect to a network. Every NIC has its own MAC address that identifies the PC on the network.
20) What is WAN?
WAN stands for Wide Area Network. It is an interconnection of computers and devices that are
geographically dispersed. It connects networks that are located in different regions and countries.
21) What is the importance of the OSI Physical Layer?
The physical layer does the conversion from data bits to electrical signal, and vice versa. This is
where network devices and cable types are considered and setup.
22) How many layers are there under TCP/IP?
There are four layers: the Network Layer, Internet Layer, Transport Layer and Application Layer.
23) What are proxy servers and how do they protect computer networks?
Proxy servers primarily prevent external users who identifying the IP addresses of an internal
network. Without knowledge of the correct IP address, even the physical location of the network
cannot be identified. Proxy servers can make a network virtually invisible to external users.
24) What is the function of the OSI Session Layer?
This layer provides the protocols and means for two devices on the network to communicate with
each other by holding a session. This includes setting up the session, managing information
exchange during the session, and tear-down process upon termination of the session.
25) What is the importance of implementing a Fault Tolerance System? Are there
limitations?

Dept. of CSE, EWIT Page64


Computer Network Laboratory BCS502
A fault tolerance system ensures continuous data availability. This is done by eliminating a single
point of failure. However, this type of system would not be able to protect data in some cases, such
as in accidental deletions.
26) What does 10Base-T mean?
The 10 refers to the data transfer rate, in this case is 10Mbps. The word Base refers to base band, as
oppose to broad band. T means twisted pair, which is the cable used for that network.
27) What is a private IP address?
Private IP addresses are assigned for use on intranets. These addresses are used for internal networks
and are not routable on external public networks. These ensures that no conflicts are present among
internal networks while at the same time the same range of private IP addresses are reusable for
multiple intranets since they do not "see" each other.
28) What is NOS?
NOS, or Network Operating System, is specialized software whose main task is to provide network
connectivity to a computer in order for it to be able to communicate with other computers and
connected devices.
29) What is DoS?
DoS, or Denial-of-Service attack, is an attempt to prevent users from being able to access the
internet or any other network services. Such attacks may come in different forms and are done by a
group of perpetuators. One common method of doing this is to overload the system server so it
cannot anymore process legitimate traffic and will be forced to reset.
30) What is OSI and what role does it play in computer networks?
OSI (Open Systems Interconnect) serves as a reference model for data communication. It is made up
of 7 layers, with each layer defining a particular aspect on how network devices connect and
communicate with one another. One layer may deal with the physical media used, while another
layer dictates how data is actually transmitted across the network.
31) What is the purpose of cables being shielded and having twisted pairs?
The main purpose of this is to prevent crosstalk. Crosstalks are electromagnetic interferences or
noise that can affect data being transmitted across cables.
32) What is the advantage of address sharing?
By using address translation instead of routing, address sharing provides an inherent security benefit.
That's because host PCs on the Internet can only see the public IP address of the external interface on
the computer that provides address translation and not the private IP addresses on the internal
network.
33) What are MAC addresses?
MAC, or Media Access Control, uniquely identifies a device on the network. It is also known as
physical address or Ethernet address. A MAC address is made up of 6-byte parts.
34) What is the equivalent layer or layers of the TCP/IP Application layer in terms of OSI
reference model?
The TCP/IP Application layer actually has three counterparts on the OSI model: the Session layer,
Presentation Layer and Application Layer.
35) How can you identify the IP class of a given IP address?

Dept. of CSE, EWIT Page65


Computer Network Laboratory BCS502
By looking at the first octet of any given IP address, you can identify whether it's Class A, B or C. If
the first octet begins with a 0 bit, that address is Class A. If it begins with bits 10 then that address is
a Class B address. If it begins with 110, then it's a Class C network.
36) What is the main purpose of OSPF?
OSPF, or Open Shortest Path First, is a link-state routing protocol that uses routing tables to
determine the best possible path for data exchange.
37) What are firewalls?
Firewalls serve to protect an internal network from external attacks. These external threats can be
hackers who want to steal data or computer viruses that can wipe out data in an instant. It also
prevents other users from external networks from gaining access to the private network.
38) Describe star topology
Star topology consists of a central hub that connects to nodes. This is one of the easiest to setup and
maintain.
39) What are gateways?
Gateways provide connectivity between two or more network segments. It is usually a computer that
runs the gateway software and provides translation services. This translation is a key in allowing
different systems to communicate on the network.
40) What is the disadvantage of a star topology?
One major disadvantage of star topology is that once the central hub or switch get damaged, the
entire network becomes unusable.
41) What is SLIP?
SLIP, or Serial Line Interface Protocol, is actually an old protocol developed during the early UNIX
days. This is one of the protocols that are used for remote access.
42) Give some examples of private network addresses.
10.0.0.0 with a subnet mask of 255.0.0.0
172.16.0.0 with subnet mask of 255.240.0.0
192.168.0.0 with subnet mask of 255.255.0.0
43) What is tracert?
Tracert is a Windows utility program that can used to trace the route taken by data from the router to
the destination network. It also shows the number of hops taken during the entire transmission route.
44) What are the functions of a network administrator?
A network administrator has many responsibilities that can be summarize into 3 key functions:
installation of a network, configuration of network settings, and maintenance/troubleshooting of
networks.
45) Describe at one disadvantage of a peer to peer network.
When you are accessing the resources that are shared by one of the workstations on the network, that
workstation takes a performance hit.
46) What is Hybrid Network?
A hybrid network is a network setup that makes use of both client-server and peer-to-peer
architecture.
47) What is DHCP?

Dept. of CSE, EWIT Page66


Computer Network Laboratory BCS502
DHCP is short for Dynamic Host Configuration Protocol. Its main task is to automatically assign an
IP address to devices across the network. It first checks for the next available address not yet taken
by any device, then assigns this to a network device.
48) What is the main job of the ARP?
The main task of ARP or Address Resolution Protocol is to map a known IP address to a MAC layer
address.
49) What is TCP/IP?
TCP/IP is short for Transmission Control Protocol / Internet Protocol. This is a set of protocol layers
that is designed to make data exchange possible on different types of computer networks, also
known as heterogeneous network.
50) How can you manage a network using a router?
Routers have built in console that lets you configure different settings, like security and data logging.
You can assign restrictions to computers, such as what resources it is allowed access, or what
particular time of the day they can browse the internet. You can even put restrictions on what
websites are not viewable across the entire network.
51) What protocol can be applied when you want to transfer files between different platforms,
such between UNIX systems and Windows servers?
Use FTP (File Transfer Protocol) for file transfers between such different servers. This is possible
because FTP is platform independent.
52) What is the use of a default gateway?
Default gateways provide means for the local networks to connect to the external network. The
default gateway for connecting to the external network is usually the address of the external router
port.
53) One way of securing a network is through the use of passwords. What can be considered as
good passwords?
Good passwords are made up of not just letters, but by combining letters and numbers. A password
that combines uppercase and lowercase letters is favorable than one that uses all upper case or all
lower case letters. Passwords must be not words that can easily be guessed by hackers, such as dates,
names, favorites, etc. Longer passwords are also better than short ones.
54) What is the proper termination rate for UTP cables?
The proper termination for unshielded twisted pair network cable is 100 ohms.
55) What is netstat?
Netstat is a command line utility program. It provides useful information about the current TCP/IP
settings of a connection.
56) What is the number of network IDs in a Class C network?
For a Class C network, the number of usable Network ID bits is 21. The number of possible network
IDs is 2 raised to 21 or 2,097,152. The number of host IDs per network ID is 2 raised to 8 minus 2,
or 254.
57) What happens when you use cables longer than the prescribed length?
Cables that are too long would result in signal loss. This means that data transmission and reception
would be affected, because the signal degrades over length.

Dept. of CSE, EWIT Page67


Computer Network Laboratory BCS502
58) What common software problems can lead to network defects?
Software related problems can be any or a combination of the following:
- client server problems
- application conflicts
- error in configuration
- protocol mismatch
- security issues
- user policy and rights issues
59) What is ICMP?
ICMP is Internet Control Message Protocol. It provides messaging and communication for protocols
within the TCP/IP stack. This is also the protocol that manages error messages that are used by
network tools such as PING.
60) What is Ping?
Ping is a utility program that allows you to check connectivity between network devices on the
network. You can ping a device by using its IP address or device name, such as a computer name.
61) What is peer to peer?
Peer to peer are networks that does not reply on a server. All PCs on this network act as individual
workstations.
62) What is DNS?
DNS is Domain Name System. The main function of this network service is to provide host names to
TCP/IP address resolution.
63) What advantages does fiber optics have over other media?
One major advantage of fiber optics is that is it less susceptible to electrical interference. It also
supports higher bandwidth, meaning more data can be transmitted and received. Signal degrading is
also very minimal over long distances.
64) What is the difference between a hub and a switch?
A hub acts as a multiport repeater. However, as more and more devices connect to it, it would not be
able to efficiently manage the volume of traffic that passes through it. A switch provides a better
alternative that can improve the performance especially when high traffic volume is expected across
all ports.
65) What are the different network protocols that are supported by Windows RRAS services?
There are three main network protocols supported: NetBEUI, TCP/IP, and IPX.
66) What are the maximum networks and hosts in a class A, B and C network?
For Class A, there are 126 possible networks and 16,777,214 hosts
For Class B, there are 16,384 possible networks and 65,534 hosts
For Class C, there are 2,097,152 possible networks and 254 hosts
67) What is the standard color sequence of a straight-through cable?
orange/white, orange, green/white, blue, blue/white, green, brown/white, brown.
68) What protocols fall under the Application layer of the TCP/IP stack?
The following are the protocols under TCP/IP Application layer: FTP, TFTP, Telnet and SMTP.
69) You need to connect two computers for file sharing. Is it possible to do this without using a
hub or router?

Dept. of CSE, EWIT Page68


Computer Network Laboratory BCS502
Yes, you can connect two computers together using only one cable. A crossover type cable can be
use in this scenario. In this setup, the data transmit pin of one cable is connected to the data receive
pin of the other cable, and vice versa.
70) What is ipconfig?
Ipconfig is a utility program that is commonly used to identify the addresses information of a
computer on a network. It can show the physical address as well as the IP address.
71) What is the difference between a straight-through and crossover cable?
A straight-through cable is used to connect computers to a switch, hub or router. A crossover cable is
used to connect two similar devices together, such as a PC to PC or Hub to hub.
72) What is client/server?
Client/server is a type of network wherein one or more computers act as servers. Servers provide a
centralized repository of resources such as printers and files. Clients refers to workstation that access
the server.
73) Describe networking.
Networking refers to the inter connection between computers and peripherals for data
communication.
Networking can be done using wired cabling or through wireless link.
74) When you move the NIC cards from one PC to another PC, does the MAC address gets
transferred as well?
Yes, that's because MAC addresses are hard-wired into the NIC circuitry, not the PC. This also
means that a PC can have a different MAC address when the NIC card was replace by another one.
75) Explain clustering support
Clustering support refers to the ability of a network operating system to connect multiple servers in a
fault-tolerant group. The main purpose of this is the in the event that one server fails, all processing
will continue on with the next server in the cluster.
76) In a network that contains two servers and twenty workstations, where is t he best place to
install an Anti-virus program?
An anti-virus program must be installed on all servers and workstations to ensure protection. That's
because individual users can access any workstation and introduce a computer virus when plugging
in their removable hard drives or flash drives.
77) Describe Ethernet.
Ethernet is one of the popular networking technologies used these days. It was developed during the
early 1970s and is based on specifications as stated in the IEEE. Ethernet is used in local area
networks.
78) What are some drawbacks of implementing a ring topology?
In case one workstation on the network suffers a malfunction, it can bring down the entire network.
Another drawback is that when there are adjustments and reconfigurations needed to be performed
on a particular part of the network, the entire network has to be temporarily brought down as well.
79) What is the difference between CSMA/CD and CSMA/CA?
CSMA/CD, or Collision Detect, retransmits data frames whenever a collision occurred. CSMA/CA,
or Collision Avoidance, will first broadcast intent to send prior to data transmission.
80) What is SMTP?

Dept. of CSE, EWIT Page69


Computer Network Laboratory BCS502
SMTP is short for Simple Mail Transfer Protocol. This protocol deals with all Internal mail, and
provides the necessary mail delivery services on the TCP/IP protocol stack.
81) What is multicast routing?
Multicast routing is a targeted form of broadcasting that sends message to a selected group of user,
instead of sending it to all users on a subnet.
82) What is the importance of Encryption on a network?
Encryption is the process of translating information into a code that is unreadable by the user. It is
then translated back or decrypted back to its normal readable format using a secret key or password.
Encryption help ensure that information that is intercepted halfway would remain unreadable
because the user has to have the correct password or key for it.
83) How are IP addresses arranged and displayed?
IP addresses are displayed as a series of four decimal numbers that are separated by period or dots.
Another term for this arrangement is the dotted decimal format. An example is 192.168.101.2
84) Explain the importance of authentication.
Authentication is the process of verifying a user's credentials before he can log into the network. It is
normally performed using a username and password. This provides a secure means of limiting the
access from unwanted intruders on the network.
85) What do mean by tunnel mode?
This is a mode of data exchange wherein two communicating computers do not use IPSec
themselves. Instead, the gateway that is connecting their LANs to the transit network creates a
virtual tunnel that uses the IPSec protocol to secure all communication that passes through it.
86) What are the different technologies involved in establishing WAN links?
Analog connections - using conventional telephone lines; Digital connections - using digitalgrade
telephone lines; switched connections - using multiple sets of links between sender and receiver to
move data.
87) What is one advantage of mesh topology?
In the event that one link fails, there will always be another available. Mesh topology is actually one
of the most fault-tolerant network topology.
88) When troubleshooting computer network problems, what common hardware-related
problems can occur?
A large percentage of a network is made up of hardware. Problems in these areas can range from
malfunctioning hard drives, broken NICs and even hardware startups. Incorrectly hardware
configuration is also one of those culprits to look into.
89) What can be done to fix signal attenuation problems?
A common way of dealing with such a problem is to use repeaters and hub, because it will help
regenerate the signal and therefore prevent signal loss. Checking if cables are properly terminated is
also a must.
90) How does dynamic host configuration protocol aid in network administration?
Instead of having to visit each client computer to configure a static IP address, the network
administrator can apply dynamic host configuration protocol to create a pool of IP addresses known
as scopes that can be dynamically assigned to clients.
91) Explain profile in terms of networking concept?

Dept. of CSE, EWIT Page70


Computer Network Laboratory BCS502
Profiles are the configuration settings made for each user. A profile may be created that puts a user in
a group, for example.
92) What is sneakernet?
Sneakernet is believed to be the earliest form of networking wherein data is physically transported
using removable media, such as disk, tapes.
93) What is the role of IEEE in computer networking?
IEEE, or the Institute of Electrical and Electronics Engineers, is an organization composed of
engineers that issues and manages standards for electrical and electronic devices. This includes
networking devices, network interfaces, cablings and connectors.
94) What protocols fall under the TCP/IP Internet Layer?
There are 4 protocols that are being managed by this layer. These are ICMP, IGMP, IP and ARP.
95) When it comes to networking, what are rights?
Rights refer to the authorized permission to perform specific actions on the network. Each user on
the network can be assigned individual rights, depending on what must be allowed for that user.
96) What is one basic requirement for establishing VLANs?
A VLAN requires dedicated equipment on each end of the connection that allows messages entering
the Internet to be encrypted, as well as for authenticating users.
97) What is IPv6?
IPv6 , or Internet Protocol version 6, was developed to replace IPv4. At present, IPv4 is being used
to control internet traffic, butis expected to get saturated in the near future. IPv6 was designed to
overcome this limitation.
98) What is RSA algorithm?
RSA is short for Rivest-Shamir-Adleman algorithm. It is the most commonly used public key
encryption algorithm in use today.
99) What is mesh topology?
Mesh topology is a setup wherein each device is connected directly to every other device on the
network. Consequently, it requires that each device have at least two network connections.

Dept. of CSE, EWIT Page71


SUBRAMANYA EDUCATION SOCIETY [R]

EAST WEST INSTITUTE OF


TECHNOLOGY
(Affiliated to VTU, Belagavi , Approved by AICTE , New Delhi & Recognized by Govt. of Karnataka)
#63 Off Magadi Road, Vishwaneedham Post,
Bengalore-91

DEPARTMENT OF COMPUTER
SCIENCE & ENGINEERING

LABORATORY MANUAL
B.E V SEMESTER
(CBCS SCHEME)
COMPUTER NETWORKS LAB
(BCS502)

You might also like