jawaharlal nehru engineering college -lm... · 2019-07-18 · mgm’s jawaharlal nehru engineering...

41
Jawaharlal Nehru Engineering College Laboratory Manual COMPUTER NETWORK -II For Third year Students 16, Nov 2005 – Rev 00 – Comp Sc – ISO 9000 Tech Document Author JNEC, Aurangabad

Upload: others

Post on 03-Apr-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Jawaharlal Nehru Engineering

College

Laboratory Manual

COMPUTER NETWORK -II

For

Third year Students

16, Nov 2005 – Rev 00 – Comp Sc – ISO 9000 Tech Document

Author JNEC, Aurangabad

Page 2: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

FOREWORD

It is my great pleasure to present this laboratory manual for third year engineering students for the subject of Computer network -II As a student, many of you may be wondering with some of the questions in your mind regarding the subject and exactly what has been tried is to answer through this manual.

As you may be aware that MGM has already been awarded with ISO 9001:2000 certification and it is our endure to technically equip our students taking the advantage of the procedural aspects of ISO 9001:2000 Certification.

Faculty members are also advised that covering these aspects in initial stage itself, will greatly relieve them in future as much of the load will be taken care by the enthusiasm energies of the students once they are

conceptually clear.

Dr. S.D.Deshmukh

Principal

Page 3: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

LABORATORY MANUAL CONTENTS

This manual is intended for the third year students of Engineering in the

subject of Computer network. This manual typically contains practical/lab sessions related Computer network -II implemented in C covering various aspects related the subject to enhanced understanding.

Students are advised to thoroughly go through this manual rather than only topics mentioned in the syllabus as practical aspects are the key to understanding and conceptual visualization of theoretical aspects covered in the books.

Good Luck for your Enjoyable Laboratory Sessions

Dr. V .B. Musande Ms.T.R.Ambekar

HOD,CSE Asst. Prof., CSE Dept.

Page 4: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

MGM’s

Jawaharlal Nehru Engineering College, Aurangabad

Department of Computer Science and Engineering

Vision of CSE Department:

To develop computer engineers with necessary analytical ability and human values who can

creatively design, implement a wide spectrum of computer systems for welfare of the society.

Mission of the CSE Department:

I. Preparing graduates to work on multidisciplinary platforms associated with their

professional position both independently and in a team environment.

II. Preparing graduates for higher education and research in computer science and

engineering enabling them to develop systems for society development.

Programme Educational Objectives:

Graduates will be able to

I. To analyze, design and provide optimal solution for Computer Science & Engineering and multidisciplinary problems.

II. To pursue higher studies and research by applying knowledge of mathematics and fundamentals of computer science.

III. To exhibit professionalism, communication skills and adapt to current trends by

engaging in lifelong learning.

Page 5: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Programme Outcomes (POs):

Engineering Graduates will be able to: 1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering

fundamentals, and an engineering specialization to the solution of complex engineering

problems. 2. 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.

3. 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.

4. 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.

5. 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.

6. 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. 7. Environment and sustainability : Understand the impact of the professional engineering

solutions in societal and environmental contexts, and demonstrate the knowledge o f, and need for sustainable development.

8. Ethics : Apply ethical principles and commit to professional ethics and responsibilities and

norms of the engineering practice.

9. Individual and team work : Function effectively as an individual, and as a member or

leader in diverse teams, and in multidisciplinary settings. 10. 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. 11. Project management and finance : Demonstrate knowledge and understanding of the

engineering and management principles and apply these to one’s own work, as a me mber

and leader in a team, to manage projects and in multidisciplinary environments.

Page 6: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

12. 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.

SUBJECT INDEX

1.Configure of network -Assigning Ip Address ,Subnet mask, Testing Basic Connectivity,

Determine and Implement Class of Ip Address .

2.Implement Unicast Routing Algorithm.( Distance Vector Routing Algorithm)

3.Implement Unicast Routing Algorithm.( Link State Routing Algorithm)

4.Implementation of Multicast or Broadcast routing algorithm.

5.Implementation of Congestion Control Algorithm (Leaky Bucket Algorithm.)

6.Implementation of Congestion Control Algorithm (Token Bucket Algorithm.)

7.Simulation or implemetation of DHCP.

8.Simulation or implemetation of DNS .

9.Simulation or implemetation of FTP.

10.Design an an enterprise network by using cisco packet tracer.

11.Analysis of enterprise Network Monitor Tool such as wireshark /Nagios.

12.Implementation of chatting application using socket programming.

Page 7: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.: 1

Title: Configure of network -Assigning Ip Address ,Subnet mask, Testing Basic

Connectivity, Determine and Implement Class of Ip Address

Objective: Student should be able to Configure of network

Theory:

IP Address Configuration Take the following steps to configure the IP address of an interface.

Step 1: Enter privileged EXEC mode: Router>enable password

Step 2: Enter the configure terminal command to enter global configuration mode.

Router#config terminal

Step 3: Enter the interface type slot/port (for Cisco 7000 series) or interface type port (for Cisco

2500 series) to enter the interface configuration mode. Example: Router (config)#interface

ethernet 0/1 Step 4: Enter the IP address and subnet mask of the interface using the ip address

ipaddress subnetmask command. Example, Router (config- if)#ip address 192.168.10.1

255.255.255.0

Step 5: Exit the configuration mode by pressing Ctrl-Z Router(config- if)#[Ctrl-

Z]EXPERIMENT-6

IP-ADDRESSING PROGRAM DEFINITION: To write a program for IP addressing

classification problem. PROGRAM DESCRIPTION: In this program based on the type of

classification we divide the IP addresses. The user gives the input address based on conclusions

st displays the category of the address.

Page 8: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Internet Protocol hierarchy contains several classes of IP Addresses to be used efficiently in

various situations as per the requirement of hosts per network. Broadly, the IPv4 Addressing

system is divided into five classes of IP Addresses. All the five classes are identified by the

first octet of IP Address.

Internet Corporation for Assigned Names and Numbers is responsible for assigning IP

addresses.

The first octet referred here is the left most of all. The octets numbered as follows depicting

dotted decimal notation of IP Address:

The number of networks and the number of hosts per class can be derived by this formula:

When calculating hosts' IP addresses, 2 IP addresses are decreased because they cannot be

assigned to hosts, i.e. the first IP of a network is network number and the last IP is reserved for

Broadcast IP.

Class A Address

The first bit of the first octet is always set to 0 (zero). Thus the first octet ranges from 1 – 127,

i.e.

Page 9: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Class A addresses only include IP starting from 1.x.x.x to 126.x.x.x only. The IP range

127.x.x.x is reserved for loopback IP addresses.

The default subnet mask for Class A IP address is 255.0.0.0 which implies that Class A

addressing can have 126 networks (27-2) and 16777214 hosts (224-2).

Class A IP address format is thus: 0NNNNNNN.HHHHHHHH.HHHHHHHH.HHHHHHHH

Class B Address

An IP address which belongs to class B has the first two bits in the first octet set to 10, i.e.

Class B IP Addresses range from 128.0.x.x to 191.255.x.x. The default subnet mask for Class

B is 255.255.x.x.

Class B has 16384 (214) Network addresses and 65534 (216-2) Host addresses.

Class B IP address format is: 10NNNNNN.NNNNNNNN.HHHHHHHH.HHHHHHHH

Class C Address

The first octet of Class C IP address has its first 3 bits set to 110, that is:

Class C IP addresses range from 192.0.0.x to 223.255.255.x. The default subnet mask for Class

C is 255.255.255.x.

Class C gives 2097152 (221) Network addresses and 254 (28-2) Host addresses.

Class C IP address format is: 110NNNNN.NNNNNNNN.NNNNNNNN.HHHHHHHH

Class D Address

Very first four bits of the first octet in Class D IP addresses are set to 1110, giving a range of:

Class D has IP address rage from 224.0.0.0 to 239.255.255.255. Class D is reserved for

Multicasting. In multicasting data is not destined for a particular host, that is why there is no

need to extract host address from the IP address, and Class D does not have any subnet mask.

Page 10: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Class E Address

This IP Class is reserved for experimental purposes only for R&D or Study. IP addresses in

this class ranges from 240.0.0.0 to 255.255.255.254. Like Class D, this class too is not

equipped with any subnet mask.

Testing Basic Connectivity

The ping command tests whether a remote host can be reached from your computer. This

simple function is extremely useful for testing the network connection, independent of the

application in which the original problem was detected. ping allows you to determine whether

further testing should be directed toward the network connection (the lower layers) or the

application (the upper layers). If ping shows that packets can travel to the remote system and

back, the user's problem is probably in the upper layers. If packets can't make the round trip,

lower protocol layers are probably at fault.

Frequently a user reports a network problem by stating that he can't telnet (or ftp, or send email,

or whatever) to some remote host. He then immediately qualifies this statement with the

announcement that it worked before. In cases like this, where the ability to connect to the

remote host is in question, ping is a very useful tool.

Using the hostname provided by the user, ping the remote host. If your ping is successful, have

the user ping the host. If the user's ping is also successful, concentrate your further analysis on

the specific application that the user is having trouble with. Perhaps the user is attempting

to telnet to a host that only provides anonymous ftp. Perhaps the host was down when the user

tried his application. Have the user try it again, while you watch or listen to every detail of what

he is doing. If he is doing everything right and the application still fails, detailed analysis of the

application with snoop and coordination with the remote system administrator may be needed.

If your ping is successful and the user's ping fails, concentrate testing on the user's system

configuration, and on those things that are different about the user's path to the remote host,

when compared to your path to the remote host.

If your ping fails, or the user's ping fails, pay close attention to any error messages. The error

messages displayed by ping are helpful guides for planning further testing. The details of the

Page 11: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

messages may vary from implementation to implementation, but there are only a few basic

types of errors:

Unknown host

The remote host's name cannot be resolved by name service into an IP address. The

name servers could be at fault (either your local server or the remote system's server),

the name could be incorrect, or something could be wrong with the network between

your system and the remote server. If you know the remote host's IP address, try

to ping that. If you can reach the host using its IP address, theproblem is with name

service. Use nslookup or dig to test the local and remote servers, and to check the

accuracy of the host name the user gave you.

Network unreachable

The local system does not have a route to the remote system. If the numeric IP address

was used on the ping command line, re-enter the ping command using the hostname.

This eliminates the possibility that the IP address was entered incorrect ly, or that you

were given the wrong address. If a routing protocol is being used, make sure it is running

and check the routing table with netstat. If RIP is being used, ripquery will check the

contents of the RIP updates being received. If a static default route is being used, re-

install it. If everything seems fine on the host, check its default gateway for routing

problems.

No answer

The remote system did not respond. Most network utilities have some version of this

message. Some ping implementations print the message "100% packet

loss." telnet prints the message "Connection timed out" and sendmail returns the error

"cannot connect." All of these errors mean the same thing. The local system has a route

to the remote system, but it receives no response from the remote system to any of the

packets it sends.

There are many possible causes of this problem. The remote host may be down. Either

the local or the remote host may be configured incorrectly. A gateway or circuit between

the local host and the remote host may be down. The remote host may have routing

problems. Only additional testing can isolate the cause of the problem. Carefully check

the local configuration using netstat and ifconfig. Check the route to the remote system

with traceroute. Contact the administrator of the remote system and report the problem.

Page 12: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

All of the tools mentioned here will be discussed later in this chapter. However, before

leaving ping, let's look more closely at the command and the statistics it displays.

11.3.1 The ping Command

The basic format of the ping command on a Solaris system is: [2]

[2] Check your system's documentation. ping varies slightly from system to system. On Linux,

the format shown above would be: ping [-c count] [-s packetsize] host

ping host [packetsize] [count]

host

The hostname or IP address of the remote host being tested. Use the hostname or address

provided by the user in the trouble report.

packetsize

Defines the size in bytes of the test packets. This field is required only if the count field is going to be used. Use the default packetsize of 56 bytes.

count

The number of packets to be sent in the test. Use the count field, and set the value low.

Otherwise, the ping command may continue to send test packets until you interrupt it, usually by pressing CTRL-C (^C). Sending excessive numbers of test packets is not a

good use of network bandwidth and system resources. Usually five packets are sufficient for a test.

Network and host address

The network or host portion of the address cannot be all ones or all zeros. As an

example, the Class A address of 118.0.0.5 is a valid IP address. The network portion, or first 8

bits, which are equal to 118, is not all zero and the host portion, or last 24 bits, is not all zeros or

all ones. If the host portion were all zeros, it would be the network address itself. If the host

portion were all ones, it would be a broadcast for the network address. The value of any octet

can never be greater than decimal 255 or binary 11111111.

Page 13: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Class 1st Octet

Decimal

Range

1st Octet

High

Order

Bits

Network/Host

ID

(N=Network,

H=Host)

Default

Subnet Mask

Number

of

Networks

Hosts per

Network

(Usable

Addresses)

A 1-126* 0 N.H.H.H 255.0.0.0 126(27 -

2)

16,777,214

(224 - 2)

B 128-191 10 N.N.H.H 255.255.0.0 16,382

(214 - 2)

65,534

(216 - 2)

C 192-223 110 N.N.N.H 255.255.255.0 2,097,150

(221 - 2)

254(28 - 2)

D 224-239 1110 Reserved for Multicasting

E 240-254 11110 Experimental; used for research

Page 14: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Conclusion:

Hence we studied and implement program Configure of network -Assigning

Ip Address ,Subnet mask, Testing Basic Connectivity…

Page 15: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No. :2

Title: Implement Unicast Routing Algorithm.( Distance Vector Routing

Algorithm)

Objective: Student should be able to understand and implement the program of unicasting .

Theory: Distance vector

Theory: Routing algorithm is a part of network layer software which is responsible

for deciding which output line an incoming packet should be transmitted on.

If the subnet uses datagram internally, this decision must be made anew for every arriving data packet since the best route may have changed since last

time. If the subnet uses virtual circuits internally, routing decisions are made only when a new established route is being set up. The latter case is sometimes called session routing, because a rout remains in force for an entire

user session (e.g., login session at a terminal or a file).

Routing algorithms can be grouped into two major classes: adaptive and nonadaptive. Nonadaptive algorithms do not base their routing decisions on measurement or estimates of current traffic and topology. Instead, the choice

of route to use to get from I to J (for all I and J) is compute in advance, offline, and downloaded to the routers when the network ids booted. This

procedure is sometime called static routing.

Adaptive algorithms, in contrast, change their routing decisions to reflect

changes in the topology, and usually the traffic as well. Adaptive algorithms differ in where they get information (e.g., locally, from adjacent routers, or

from all routers), when they change the routes (e.g., every ∆T sec, when the load changes, or when the topology changes), and what metric is used for optimization (e.g., distance, number of hops, or estimated transit time).

Two algorithms in particular, distance vector routing and link state routing

are the most popular. Distance vector routing algorithms operate by having each router maintain a table (i.e., vector) giving the best known distance to each destination and which line to get there. These tables are updated by

exchanging information with the neighbors.

The distance vector routing algorithm is sometimes called by other names, including the distributed Bellman-Ford routing algorithm and the Ford-Fulkerson algorithm, after the researchers who developed it (Bellman, 1957;

and Ford and Fulkerson, 1962). It was the original ARPANET routing algorithm and was also used in the Internet under the RIP and in early

Page 16: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

versions of DECnet and Novell’s IPX. AppleTalk and Cisco routers use improved distance vector protocols.

In distance vector routing, each router maintains a routing table indexed by, and containing one entry for, each router in subnet. This entry contains

two parts: the preferred out going line to use for that destination, and an estimate of the time or distance to that destination. The metric used might be number of hops, time delay in milliseconds, total number of packets queued

along the path, or something similar.

The router is assumed to know the “distance” to each of its neighbor. If the metric is hops, the distance is just one hop. If the metric is queue length, the router simply examines each queue. If the metric is delay, the router can

measure it directly with special ECHO packets hat the receiver just time stamps and sends back as fast as possible.

The Count to Infinity Problem.

Distance vector routing algorithm reacts rapidly to good news, but

leisurely to bad news. Consider a router whose best route to destination X is large. If on the next exchange neighbor A suddenly reports a short delay to X,

the router just switches over to using the line to A to send traffic to X. In one vector exchange, the good news is processed.

To see how fast good news propagates, consider the five node (linear) subnet of following figure, where the delay metric is the number of hops.

Suppose A is down initially and all the other routers know this. In other words, they have all recorded the delay to A as infinity.

A B C D E A B C D E _____ _____ _____ _____ _____ _____ _____ _____

∞ ∞ ∞ ∞ Initially 1 2 3 4 Initially

1 ∞ ∞ ∞ After 1 exchange 3 2 3 4 After 1 exchange

1 2 ∞ ∞ After 2 exchange 3 3 3 4 After 2 exchange

1 2 3 ∞ After 3 exchange 5 3 5 4 After 3 exchange

1 2 3 4 After 4 exchange 5 6 5 6 After 4 exchange

7 6 7 6 After 5 exchange

7 8 7 8 After 6 exchange

:

∞ ∞ ∞ ∞

Many ad hoc solutions to the count to infinity problem have been proposed

in the literature, each one more complicated and less useful than the one

before it. The split horizon algorithm works the same way as distance vector routing, except that the distance to X is not reported on line that packets for X

are sent on (actually, it is reported as infinity). In the initial state of right figure, for example, C tells D the truth about distance to A but C tells B that its distance to A is infinite. Similarly, D tells the truth to E but lies to C.

Page 17: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Algorithm: • c(x,v) = cost for direct link from x to v

–Node x maintains costs of direct links c(x,v)

• Dx(y) = estimate of least cost from x to y

–Node x maintains distance vector Dx = [Dx(y): y _ N ]

• Node x maintains its neighbors’ distance vectors

– For each neighbor v, x maintains Dv = [Dv(y): y _ N ]

• Each node v periodically sends Dv to its neighbors

– And neighbors update their own distance vectors

–Dx(y) _ minv{c(x,v) + Dv(y)} for each node y ε N

• Over time, the distance vector Dx converges

Page 18: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Program:

#include <conio.h> #include <iostream.h> #define MAX 10 int n; class router { char adj_new[MAX], adj_old[MAX]; int table_new[MAX], table_old[MAX]; public: router(){ for(int i=0;i<MAX;i++) table_old[i]=table_new[i]=99; } void copy(){ for(int i=0;i<n;i++) { adj_old[i] =adj_new[i]; table_old[i]=table_new[i]; } } int equal() { for(int i=0;i<n;i++) if(table_old[i]!=table_new[i]||adj_new[i]!=adj_old[i])return 0; return 1; } void input(int j) { cout<<"Enter 1 if the corresponding router is adjacent to router" <<(char)('A'+j)<<" else enter 99: "<<endl<<" "; for(int i=0;i<n;i++) if(i!=j) cout<<(char)('A'+i)<<" "; cout<<"\nEnter matrix:"; for(i=0;i<n;i++) { if(i==j) table_new[i]=0; else cin>>table_new[i]; adj_new[i]= (char)('A'+i); } cout<<endl; } void display(){ cout<<"\nDestination Router: "; for(int i=0;i<n;i++) cout<<(char)('A'+i)<<" "; cout<<"\nOutgoing Line: "; for(i=0;i<n;i++) cout<<adj_new[i]<<" "; cout<<"\nHop Count: "; for(i=0;i<n;i++) cout<<table_new[i]<<" "; } void build(int j) { for(int i=0;i<n;i++) for(int k=0;(i!=j)&&(k<n);k++)

Page 19: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

if(table_old[i]!=99) if((table_new[i]+r[i].table_new[k])<table_new[k]) { table_new[k]=table_new[i]+r[i].table_new[k]; adj_new[k]=(char)('A'+i); } } } r[10]; void build_table() { int i=0, j=0; while(i!=n) { for(i=j;i<n;i++) { r[i].copy(); r[i].build(i); } for(i=0;i<n;i++) if(!r[i].equal()) { j=i; break; } } } void main() { clrscr(); cout<<"Enter the number the routers(<"<<MAX<<"): "; cin>>n; for(int i=0;i<n;i++) r[i].input(i); build_table(); for(i=0;i<n;i++) { cout<<"Router Table entries for router "<<(char)('A'+i)<<":-"; r[i].display(); cout<<endl<<endl; } getch(); }

Output:

Enter the number the routers: 5 Enter 1 if the corresponding is adjacent to router A else enter 99: B C D E Enter matrix:1 1 99 99 Enter 1 if the corresponding is adjacent to router B else enter 99: A C D E Enter matrix:1 99 99 99 Enter 1 if the corresponding is adjacent to router C else enter 99: A B D E Enter matrix:1 99 1 1 Enter 1 if the corresponding is adjacent to router D else enter 99: A B C E Enter matrix:99 99 1 99 Enter 1 if the corresponding is adjacent to router E else enter 99: A B C D

Page 20: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Enter matrix:99 99 1 99

Conclusion:

Hence we studied and implement program evaluate distance vector routing algorithm.

Page 21: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.: 3

Title: Implement Unicast Routing Algorithm.( Link State Routing Algorithm)

Objective: Student should be able to understand and implement the program of link state routing algorithm.

THEORY:

Link State Routing Algorithm

A link-state routing protocol is one of the two main classes of routing protocols used in packet

switching networks for computer communications (the other is the distance-vector routing

protocol). Examples of link-state routing protocols include open shortest path first (OSPF)

and intermediate system to intermediate system (IS-IS).

The link-state protocol is performed by every switching node in the network (i.e., nodes that

are prepared to forward packets; in the Internet, these are called routers). The basic concept of

link-state routing is that every node constructs a map of the connectivity to the network, in the

form of a graph, showing which nodes are connected to which other nodes. Each node then

independently calculates the next best logical path from it to every possible destination in the

network. The collection of best paths will then form the node's routing table.

This contrasts with distance-vector routing protocols, which work by having each node share

its routing table with its neighbours. In a link-state protocol the only information passed

between nodes is connectivity related.

Program : #include<stdio.h> main() { int n,a[10][10],i,j,k; printf("\n ENTER THE NO.OF <span id="IL_AD5" class="IL_AD">NODES</span>: ");

Page 22: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

scanf("%d",&n); printf("\n <span id="IL_AD3" class="IL_AD">ENTER THE MATRIX</span> ELEMENTS: "); for(i=0;i<n;i++) { printf("\nENTER THE DISTANCE FOR NODE:%d\n",i+1); for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } for(i=0;i<n;i++) { printf("THE LINK STATE STATE PACKETS FOR NODE:%d\n",i+1); printf("\n NODE\tDISTANCE\n"); for(j=0;j<n;j++) { if(a[i][j]!=0&&a[i][j]!=-1) { printf("%d\t%d\n",j+1,a[i][j]); } } printf("\n\n"); } }

Page 23: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Output:

Conclusion: Hence we studied and implement program link state routing algorithm.

Page 24: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.:4 Title: Implementation of Congestion Control Algorithm (Leaky Bucket Algorithm.)

Objective: Student should be able to understand and implement the program leaky bucket algorithm.

Theory:

Theory

The congesting control algorithms are basically divided into two groups: open loop and closed

loop. Open loop solutions attempt to solve the problem by good design, in essence, to make sure

it does not occur in the first place. Once the system is up and running, midcourse corrections are

not made. Open loop algorithms are further divided into ones that act at source versus ones that

act at the destination.

In contrast, closed loop solutions are based on the concept of a feedback loop if there is any

congestion. Closed loop algorithms are also divided into two sub categories: explicit feedback

and implicit feedback. In explicit feedback algorithms, packets are sent back from the point of

congestion to warn the source. In implicit algorithm, the source deduces the existence of

congestion by making local observation, such as the time needed for acknowledgment to come

back.

The presence of congestion means that the load is (temporarily) greater than the resources (in

part of the system) can handle. For subnets that use virtual circuits internally, these methods can

be used at the network layer.

Another open loop method to help manage congestion is forcing the packet to be transmitted

at a more predictable rate. This approach to congestion management is widely used in ATM

networks and is called traffic shaping.

The other method is the leaky bucket algorithm. Each host is connected to the network by an

interface containing a leaky bucket, that is, a finite internal queue. If a packet arrives at the queue

when it is full, the packet is discarded. In other words, if one or more process are already queued,

the new packet is unceremoniously discarded. This arrangement can be built into the hardware

interface or simulate d by the host operating system. In fact it is nothing other than a single

server queuing system with constant service time.

Page 25: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

The host is allowed to put one packet per clock tick onto the network. This mechanism turns

an uneven flow of packet from the user process inside the host into an even flow of packet onto

the network, smoothing out bursts and greatly reducing the chances of congestion.

Page 26: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Program:

#include<iostream.h> #include<dos.h> #include<stdlib.h> #define bucketSize 512 void bktInput(int a,int b) { if(a>bucketSize) cout<<"\n\t\tBucket overflow"; else { delay(500); while(a>b){ cout<<"\n\t\t"<<b<<" bytes outputted."; a-=b; delay(500); } if (a>0) cout<<"\n\t\tLast "<<a<<" bytes sent\t"; cout<<"\n\t\tBucket output successful"; } } void main() { int op, pktSize; randomize(); cout<<"Enter output rate : "; cin>>op; for(int i=1;i<=5;i++){ delay(random(1000)); pktSize=random(1000); cout<<"\nPacket no "<<i<<"\tPacket size = "<<pktSize; bktInput(pktSize,op); } }

Output:

Enter output rate : 100 Packet no 0 Packet size = 3 Bucket output successful Last 3 bytes sent Packet no 1 Packet size = 33 Bucket output successful Last 33 bytes sent Packet no 2 Packet size = 117 Bucket output successful

Page 27: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

100 bytes outputted. Last 17 bytes sent Packet no 3 Packet size = 95 Bucket output successful Last 95 bytes sent Packet no 4 Packet size = 949 Bucket overflow

Conclusion: Hence we studied and implement program for leaky bucket algorithm.

Page 28: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.:5 Title: Implementation of Multicast or Broadcast routing algorithm. Objective: Student should be able to understand and implement the program of of Multicast or Broadcast routing algorithm..

Theory:

1. Broad cast refers to sending a packet to all destinations simultaneously

2. One broadcasting methos that requires no special features from subnet is for source to

simply send a distinction packet to each destination

3. This broad cast algorithm makes explicit use of sink tree for the router initiating the

broadcast, or any other convenient spanning tree.

4. This spanning tree is a subset of subnet includes all routers but contain no loops .

1. When packet arrives at router, it checks to see if packet arrived on time.

2. If so, there is an excellent chance that broadcast packet followed the best route from

router and therefore first copy arrived at router.

3. This being the case, the router forwards copies of it on all lines except the one it arrived

on.

4. If however the broadcast packet arrived on a line other than the preferred one for

reaching the source the packet is discarded as a likely duplicate.

Algorithm:

Program:

include<stdio.h> #include<string.h>

Page 29: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

#include<sys/stat.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #define MAXRECVSTRING 255 int main(int argc , char argv[]) { struct sockaddr_in client,server; int s,n; char b1[100],b2[100]; s=socket(AF_INET,SOCK_DGRAM,0); server.sin_family=AF_INET; server.sin_port=htons(2000); server.sin_addr.s_addr=inet_addr("127.0.0.1"); printf("\nClient ready....\n"); n=sizeof(server); int sock; /* Socket */ struct sockaddr_in broadcastAddr; /* Broadcast Address */ unsigned short broadcastPort; /* Port */ char recvString[MAXRECVSTRING+1]; /* Buffer for received string */ int recvStringLen; /* Length of received string */ if (argc != 2) /* Test for correct number of arguments */ { fprintf(stderr,"Usage: %s <Broadcast Port>\n", argv[0]); exit(1); } printf("\nClient ready…11111.\n"); broadcastPort = htons(argv[1]); /* First arg: broadcast port */ printf("\nClient ready….1\n"); /* Create a best-effort datagram socket using UDP */ if(sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)<0) printf("no sock created"); printf("\nClient ready….2\n"); while(1) { printf("\nClient:"); gets(b2); sendto(s,b2,sizeof(b2),0,(struct sockaddr *) &server,n); if(strcmp(b2,"end")==0) break; recvfrom(s,b1,sizeof(b1),0,NULL,NULL); printf("\nServer:%s",b1); broadcastAddr.sin_family = AF_INET; /* Internet address family */ broadcastAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ broadcastAddr.sin_port = htons(broadcastPort); /* Broadcast port */ /* Bind to the broadcast port */ bind(sock, (struct sockaddr *) &broadcastAddr, sizeof(broadcastAddr)); /* Receive a single datagram from the server */ recvStringLen = recvfrom(sock, recvString, MAXRECVSTRING, 0, NULL, 0); recvString[recvStringLen] = '\0'; printf("Received: %s\n", recvString); /* Print the received string */ } close(sock);

Page 30: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Output:

Conclusion: Hence we studied and implement program broadcast routing algorithm..

Page 31: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.:6 Title: Implementation of Congestion Control Algorithm (Token Bucket Algorithm.)

Objective: Student should be able to understand and implement the program token bucket algorithm

Theory: TOKEN BUCKET ALGORITHM

In this algorithm, the leaky bucket holds tokens, generated by a clock at the rate of one token

every ∆T sec. the token bucket algorithm does allow saving, up to the maximum size of the

bucket,n. LOGIC: The implementation of the token bucket algorithm is just a variable that

counts tokens. The counter is incremented by one every ∆T and decremented by one whenever a

packet is sent. When the counter hits zero, no packets may be sent. In the byte count variant, the

counter is incremented by k bytes every ∆T and decremented by the length of each packet

sent.Computer Networks Lab Manual 43 / 53 LEAKY BUCKET ALGORITHM AIM: To

implement the Leaky Bucket algorithm. DESCRIPTION: This algorithm is a single-server

queuing system with constant service time.The host is allowed to put one packet per clock tick

onto the network. When the packets are of variable size, it is often better to allow a fixed number

of bytes per tick, rather than just one packet. Thus if the rule is 1024 bytes per tick, a s ingle 1024

byte packet can be admitted on a tick, two 512 byte packets, four 256 byte packets, and so on. If

the residual count is too low, the next packet must wait until the next tick. LOGIC: The leaky

bucket consists of a finite queue. When a packet arrives, if there is room on the queue, it is

appended to the queue; otherwise it is discarded. At every clock tick, one packet is

transmitted(unless the queue is empty). The byte-counting leaky bucket is implemented in almost

the same way. At each tick, a counter is initialized to n. if the first packet on the queue has fewer

bytes than the current value of the counter , it is transmitted, and the counter is decremented by

that number of bytes. Additional packets may also be sent, as long as the counter is high enough.

When the counter drops below the length of the next packet on the queue, transmission stops

until the next tick, at which time the residual count is overwritten and lost. Computer Networks

Lab Manual 44 / 53 IP-ADDRES.

Page 32: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Unlike leaky bucket, token bucket allows saving, up to maximum size of bucket n. This means

that bursts of up to n packets can be sent at once, giving faster response to sudden bursts of input

• An important difference between two algorithms: token bucket throws away tokens when the

bucket is full but never discards packetswhile leaky bucket discards packets when the bucket is

full • Let token bucket capacity be C (bits), token arrival rate ρ (bps), maximum output rate M

(bps), and burst length S (s) – During burst length of S (s), tokens generated are ρS (bits), and

output burst contains a maximum of C + ρS (bits) – Also output in a maximum burst of length S

(s) is M · S (bits), thus C + ρS = MS or S = C M − ρ • Token bucket still allows large bursts,

even though the maximum burst length S can be regulated by careful selection of ρ and M • One

way to reduce the peak rate is to put a leaky bucket of a larger rate (to avoid discarding packets)

after the token bucket 122 ELEC3030 (EL336) Computer Networks S Chen Illustration

Page 33: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Program: void bktInput(int a,int b) { if(a>bucketSize) cout<<"\n\t\tBucket overflow";

else { delay(500); while(a>b){ cout<<"\n\t\t"<<b<<" bytes outputted."; a-=b; delay(500); } if (a>0) cout<<"\n\t\tLast "<<a<<" bytes sent\t";

cout<<"\n\t\tBucket output successful"; } } void main() { int op, pktSize;

randomize(); cout<<"Enter output rate : "; cin>>op; for(int i=1;i<=5;i++){ delay(random(1000)); pktSize=random(1000); cout<<"\nPacket no "<<i<<"\tPacket size =

"<<pktSize; bktInput(pktSize,op);

} }

Page 34: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Output:

Conclusion: Hence we studied and implement to perform token bucket algorithm.

Page 35: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Experiment No.:7

Title: Implementation of shortest path algorithm Objective: Student should be able to understand and implement the program shortest path algorithm.

Theory:

Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning tree. Like Prim’s

MST, we generate a SPT (shortest path tree) with given source as root. We maintain two sets,

one set contains vertices included in shortest path tree, other set includes vertices not yet

included in shortest path tree. At every step of the algorithm, we find a vertex which is in the

other set (set of not yet included) and has minimum distance from source.

Below are the detailed steps used in Dijkstra’s algorithm to find the shortest path from a single

source vertex to all other vertices in the given graph.

Algorithm

1) Create a set sptSet (shortest path tree set) that keeps track of vertices included in shortest path

tree, i.e., whose minimum distance from source is calculated and finalized. Initially, this set is

empty.

2) Assign a distance value to all vertices in the input graph. Initialize all distance values as

INFINITE. Assign distance value as 0 for the source vertex so that it is picked first.

3) While sptSet doesn’t include all vertices

….a) Pick a vertex u which is not there in sptSetand has minimum distance value.

….b) Include u to sptSet.

….c) Update distance value of all adjacent vertices of u. To update the distance values, iterate

through all adjacent vertices. For every adjacent vertex v, if sum of distance value of u (from

source) and weight of edge u-v, is less than the distance value of v, then update the distance

value of v.

Page 36: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Let us understand w ith the follow ing example:

The set sptSetis initially empty and distances assigned to vertices are {0, INF, INF, INF, INF,

INF, INF, INF} where INF indicates infinite. Now pick the vertex with minimum distance value.

The vertex 0 is picked, include it in sptSet. So sptSet becomes {0}. After including 0 to sptSet,

update distance values of its adjacent vertices. Adjacent vertices of 0 are 1 and 7. The distance

values of 1 and 7 are updated as 4 and 8. Following subgraph shows vertices and their distance

values, only the vertices with finite distance values are shown. The vertices included in SPT are

shown in green color.

Pick the vertex with minimum distance value and not already included in SPT (not in sptSET). The vertex 1 is picked and added to sptSet. So sptSet now becomes {0, 1}. Update the distance values of adjacent vertices of 1. The distance value of vertex 2 becomes 12.

Pick the vertex with minimum distance value and not already included in SPT (not in sptSET). Vertex 7 is picked. So sptSet now becomes {0, 1, 7}. Update the distance values of adjacent

Page 37: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

vertices of 7. The distance value of vertex 6 and 8 becomes f inite (15 and 9 respectively).

Pick the vertex with minimum distance value and not already included in SPT (not in sptSET).

Vertex 6 is picked. So sptSet now becomes {0, 1, 7, 6}. Update the distance values of adjacent vertices of 6. The distance value of vertex 5 and 8 are updated.

We repeat the above steps until sptSet doesn’t include all vertices of given graph. Finally, we get

the following Shortest Path Tree (SPT).

Page 38: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE
Page 39: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

Algorithm:

// A C / C++ program for Dijkstra's single source shortest path algorithm.

// The program is for adjacency matrix representation of the graph

#include <stdio.h>

#include <limits.h>

// Number of vertices in the graph

#define V 9

// A utility function to find the vertex with minimum distance value, from

// the set of vertices not yet included in shortest path tree

int minDistance(int dist[], bool sptSet[])

{

// Initialize min value

int min = INT_MAX, min_index;

for (int v = 0; v < V; v++)

if (sptSet[v] == false && dist[v] <= min)

min = dist[v], min_index = v;

return min_index;

}

// A utility function to print the constructed distance array

int printSolution(int dist[], int n)

{

printf("Vertex Distance from Source\n");

for (int i = 0; i < V; i++)

printf("%d \t\t %d\n", i, dist[i]);

}

Program:

Output:

Vertex Distance from Source

0 0

1 4

2 12

Page 40: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE

3 19

4 21

5 11

6 9

7 8

8 14

Conclusion: Hence we studied and implement to shortest path between any node.

Page 41: Jawaharlal Nehru Engineering College -LM... · 2019-07-18 · MGM’s Jawaharlal Nehru Engineering College, Aurangabad Department of Computer Science and Engineering Vision of CSE