• No results found

JNTU B.tech Computer Networks Lab Manual All Programs (1)

N/A
N/A
Protected

Academic year: 2021

Share "JNTU B.tech Computer Networks Lab Manual All Programs (1)"

Copied!
53
0
0

Loading.... (view fulltext now)

Full text

(1)

COMPUTER NETWORKS

LAB MANUAL

Prepared

by

Department of Computer Science & Engineering

(2)

Goals:

Get familiar with the C Programming Language: If you don't already know it, in this lab you will get started on learning a new programming language. Although this is not meant to be a tutorial, you will get exposed to the most basic features of the language by reading and analyzing some basic programs.

Learn to use or get better practice with Unix system calls: Operating Systems provide programmers with a range of services that can be used directly in their applications. These services are most often presented at

system calls, that is, functions that applications can use to ask the operating

systems to perform certain tasks for them. Since this course is based on the Unix operating system, we will be working exclusively with Unix system calls. These services are commonly implemented in roughly the same way across different flavors of Unix. At Bucknell, we currently work with a mixture of Sun Solaris and Intel Linux machines, so beware: depending on the platform you work there may be small differences in how these system calls are implemented. The Unix manual pages available on the computing platform will be of great help to you in understanding what specific system calls can do for your application and in how you use them. Make sure to take this opportunity to learn to navigate the manual pages effectively if you don't already know how to do that.

The C Programming Language

In this lab you will spend some time getting acquainted with the C programming language. Rather than provide you with a step-by-step tutorial in the language, we will discuss the most significant differences from C++, which you're assumed

to know.

For the experienced C++ programmer, the C language will look much more low-level, as it indeed is. We discuss some of the features of the language in more detail later on in this lab, but point out the most salient differences you will encounter in C coming from C++:

There are no classes. C is not an object-oriented language.

Comments must be enclosed in /* ... */, single-line comment // is supported only in the more recent versions of C.

The nesting of comment blocks is not allowed. Strings are simply null-terminated arrays of char.

Type checking for function arguments may be quite lax, meaning that more burden is on the programmer.

There isn't stream-based input/output (cin, cout). The available operations for I/O seem crude because they are lower-level.

(3)

Dynamic memory allocation is done via library functions such as malloc,

calloc, and free (no new / delete). You allocate and deallocate arrays of

bytes instead of "space for a data-type".

Parameter passing is exclusively by value. If you need to modify a parameter passed into a function, you must pass the pointer to the parameter.

There exist "dialects" of the C language, which define some minor syntactical differences and alternatives to type-checking. The dialect used depends, of course, on the compiler you use. Three of the most common dialects are:

Kernighan & Ritchie C (or simply K&R C, named after the creators of the language) .

ANSI C (which has is much stricter about type-checking than K&R C).

The BSD Socket API

Sockets are like Unix pipes in that they use file descriptors to define the endpoints of a communication channel. When you make the system call to create a pipe, you pass in the pointer to an integer array with two elements. The successful competion of the pipe call returns 0 and initializes the array with two file descriptors, one to which you can write and one from which you can read. The socket follows a more complex set up process which we describe below.

Creating a socket

#include <sys/types.h> #include <sys/socket.h>

int socket(int domain, int type, int protocol);

The socket call creates one single endpoint for communications, unlike pipe which returns two. If the value returned is less than 0, the call was unsuccessful and the error can be discovered through errno and perror. If the value returned is greater than or equal to 0, the call was successful and the returned value is a File-descriptor.

Althouth the AF_UNIX domain adds some interesting and flexible options for IPC within the same host, we will leave it lone for now. We are more interested in domains that allow two hosts connected to the Internet to communicate and will focus exclusively on the AF_INET for now.

The next parameter, type, can assume one of three possible values as described below:

(4)

SOCK_DGRAM: provides datagram communication semantics, that is, this is a connectionless protocol that will do its best to deliver the data without making any promises that the service is reliable. There are no guarantees that the datagrams are delivered in the order they are sent.

SOCK_STREAM: provices a bidirectional virtual circuit that is reliable and order-preserving (FIFO).

SOCK_RAW: provides the ability to send packets directly to a network device driver, enabling user space applications to provide networking protocols that are not implemented in the kernel.

The last parameter, protocol, can be left unspecified (value 0) so that the default protocol that supports the protocol family and socket type is used. In case multiple protocols exist for the selected tuple <domain, type>, then a specific protocol must be specified.

After the successful completion of the socket call, what you have is a connection endpoint that is not attached anywhere. Before any communication can happen, the socket must be associated to "something". The process of connecting the socket is an asymmetric task, that is, it is performed differently at each endpoint of the socket. Server applications (which run on "infinite loops"), create the socket, get it ready to be hooked up to something, and then wait for someone to request a connection to the socket. Client processes, on the other hand, create a socket, tell the system to which address they want to connect it, and attempt establishing the connection to the server. The server process then accepts the connection request and the socket is finally ready for communication.

Binding an address to a socket

Before we proceed, you need to understand what an Internet address and how it is represented in Unix. Header file <netinet/in.h> defines a 32-bit address for an Internet host. It actually identifies a specific network interface on a specific system on the Internet using the data structure below:

struct in_addr { __u32 s_addr; };

(5)

Demonstration of How a Header File works:

/******************************************************************

* *

* decls.h is a demonstration file to show how header file works.*

* *

******************************************************************/ int i; /* a integer variable */

float x; /* a float variable */

**************

/****************************************************************

* *

* foo.c *

* A simple C module file that contains a function called 'foo' *

* * ****************************************************************/ #include "decls.h" foo(int k) { printf("i = %d, k = %d\n", i, k); } ******************* /******************************************************* * * * main() *

* The main() function that calls the function 'foo()' *

* * *******************************************************/ #include "decls.h" int main(void) { i = 1; if (i == 0) x = 1000; else foo(-1); printf(" result x = %f\n", x); return 0; }

(6)

INDEX

1. OSI MODEL SIMULATION

2. IMPLEMTATION OF DATA LINK FRAMING METHODS

a) CHARACTER COUNT

b) BIT STUFFING AND DE STUFFING

c) CHARACTER STUFFING AND DE STUFFING

3. PARITY CHECK

a) SINGLE DIMENSIONAL DATA b) MULTI DIMENSIONAL DATA

4. EVEN AND ODD PARITY

5. IMPLEMENTATION OF CRC POLYNOMIALS 6. IMPLEMENTATION OF DATA LINK PROTOCOLS

a) UNRESTRICTED SIMPLEX PROTOCOL b) STOP AND WAIT PROTOCOL

c) NOISY CHANNEL

7. IMPLEMENTATION OF SLIDING WINDOW PROTOCOLS

a) One Bit sliding window protocol

b) GO BACK N SLIDING WINDOW PROTOCOL

c) SELECTIVE REPEAT SLIDING WINDOW PROTOCOL

8. IMPLEMENTATION OF ROUTING ALDORITHMS

a) DIJKSTRA’S ALGORITHM b) DISTANCE VECTOR ROUTING c) HIREARCHICAL ROUTING d) BROADCAST ALGORITHM

9. CONGESTION ALGORITHMS

a) TOKEN BUCKET ALGORITHM b) LEAKY BUCKET ALGORITHM

10. IP-ADDRESSING

11. ENCRYPTION ALGORITHMS

a) SUBSTITUTION CIPHER b) TRANSPOSITION CIPHER

c) DATA ENCRYPTION ALGORITHM

12. IMPLEMENTATION OF SERVERS

a) DATE SERVER b) CHAT SYSTEM

(7)
(8)

OSI MODEL

PROGRAM DEFINITION:

This is an open system interconnection program tha transmit message from sender to receiver through server different layers.

PROGRAM DESCRIPTION:

The OSI Model deals with connecting open system. This model does not specify the exact services and protocols to used in each layer. Therefore,the OSI Model is not a network architecture. This model has seven layers. They are Physical layer, Datalink layer, Presentation layer, Network layer, Session layer, Transport layer and Application layer. At sender side, each layer add the header. The length of string i.e, number of bytes are not restricted upto Session layer.

ALGORITHM:

1. Read the input string and address. 2. Add application header.

3. Print the string.

4. Add the presentation layer header. 5. Print the string.

6. Add the Session layer header. 7. Print the string.

8. Add the Transport layer header. 9. Print the string.

10. Add the Network layer header. 11. Print the string.

12. Add the Datalink layer header. 13. Print the string

14. add the physical layer header. 15. Print the string.

INPUT:

Enter the string:hai

OUTPUT:

TRANSMITTER:

APPLICATION LAYER: AH hai

PRESENTATION LAYER: PHAH hai

SESSION LAYER: SHPHAH hai

TRANSPORT LAYER: THSHPHAH hai

NETWORK LAYER: NHTHSHPHAH hai

DATALINK LAYER: DHNHTHSHPHAH hai

(9)

RECEIVER:

MESSAGE ENTERED INTO PHYSICAL LAYER

DATALINK LAYER: DHNHTHSHPHAH hai

NETWORK LAYER: NHTHSHPHAH hai

TRANSPORT LAYER: THSHPHAH hai

SESSION LAYER: SHPHAH hai

PRESENTATION LAYER: PHAH hai

(10)

IMPLEMTATION OF DATA LINK FRAMING METHODS

b) CHARACTER COUNT

c) BIT STUFFING AND DE STUFFING

(11)

CHARACTER COUNT

AIM:

Implementation of data link framing methods for counting characters in a given frame

LOGIC:

The header in the given frame is by default first frame size including the first field data bits are counted and considered as the first frame and the next field contains the next frame size and so on.

PSEUDO CODE:

1. At the sender side the user is asked to enter the number of frames he want to transmit.

2. Depending upon the input, that many number of frames are taken as input from the user and stored in a 2 by 2 matrix.

3. The length of each frame is calculated and stored in a new array. 4. While out putting the frame, the length of each frame is added to the

each frame and finally all the frames are appended and sent as a single string.

5. At the receiver side, the first number is treated as the length of the first frame and the string is extracted and displayed.

6. The next number is treated as the length of the next frame and so on.

At Sender:

INPUT:

Enter the number of frames you want to send:2 Enter the frame:1234

Enter the frame:678

OUTPUT

The transmitted frame is:512344678

At receiver:

INPUT:

Enter data 512344678

OUTPUT:

frame sizes are: 5 4 frames are:

(12)

BIT STUFFING

AIM:

Implementation of the data link framing methods for the bit stuffing in a frame.

LOGIC:

Stuffing a 0 bit in a data frame in order to differentiate the header, trailer and data.

PSEUDO CODE:

/* For given data */

1. a flag “01111110” is embedded at the starting and the ending of the data. /* stuffing of data */

2. if data bit is 1 increment count else count is zero.

3. If count is five store a zero bit after the five 1‟s in the data array. 4. Repeat step 3 till the end of data. /* De stuffing of data */

5. If the data bit is 1 increment count else count is zero.

6. If the count is five and the next bit is zero then store the next bit after zero in the data array. /* transmit the data */

7. De stuffed data is transmitted with out flags.

At sender:

INPUT:

Enter the string 1111110101

OUTPUT:

Transmitted data is: 01111110111111010101111110 Stuffed data is: 011111101111101010101111110

At Receiver:

OUTPUT:

(13)

CHARACTER STUFFING

AIM:

Implementation of data link framing methods for character stuffing in a frame.

LOGIC:

In a character data frame if a DLE is encountered between the data it is doubled and transmitted at the receiver side it is de stuffed and original data is obtained.

PSEUDO CODE:

/* Defining DLE characters */

1. As the DLE characters are non printable characters. The ASCII values of the printable characters like *,#,$ are assigned to DLE, STX, ETX. /*Stuffing the data */

2. If the ASCII value that is assigned to DLE occurs in the data array another DLE character is stuffed and stored in the array and transmitted along with starting and ending flags /* destuffing data */ 3. If the ASCII value of DLE occurs in the data array, the next bit is stored

in to the array and transmitted with out the flags.

4. Here whenever the program encounters characters like * the string DLE is added to the original string.

At Sender: INPUT: Enter Data r*gm OUTPUT: Stuffed data DLESTXrDLEDLEgmDLEETX At receiver: OUTPUT: The message: r*gm

(14)

PARITY CHECK

a) SINGLE DIMENSIONAL DATA

b) MULTI DIMENSIONAL DATA

(15)

SINGLE DIMENTIONAL (EVEN / ODD) PARITY

AIM:

Implementation of data link framing methods for even and odd parity

LOGIC:

0‟s and 1‟s are appended to the data according to the parity of the data.

PSEUDO CODE:

/* for given data */

1. if data bit is 1 increment count else count is zero /* even parity */

2. if the count mod 2 is zero then append the next bit as 0 else 1 /* odd parity */

3. if the count mod 2 is zero then append the next bit as 1 else 0

INPUT:

Enter the string 1111101

Enter the choice 1. even parity 2. odd parity 1 OUTPUT: The string is 11111010 INPUT:

Enter the string 111101

Enter the choice 1. even parity 2. odd parity 2 OUTPUT: The string is 1111010

(16)

MULTI DIMENSIONAL PARITY CHECK

AIM:

Implementation of data link framing method for horizontal row check and vertical column check for multi dimensional data

LOGIC:

0‟s and 1‟s are appended to the data accessing to the parity of the data.

PSEUDO CODE:

/* For given data */

1. if data bit is 1 increment count in row wise else count is zero.

2. if data bit is 1 increment cn in column wise else cn is zero. /* horizontal row check */

3. if count mod 2 is zero append the next bit as 0 else 1 /*vertical column check */

4. if cn mod 2 is zero append the next bit as 1 else 0 /* comparing horizontal and vertical parity checks */

5. if both the horizontal and vertical parity checks are equal then no error else error occurred at certain row and at certain column.

INPUT:

Enter size of data: 3 3 enter data: 1 0 1 1 0 1 1 1 1 Horizontal parity: 0 0 1 Vertical parity: 1 1 1

Enter received data: 1 1 1 1 0 1 1 1 1 Horizontal parity: 1 0 1 Vertical parity: 1 0 1

error is at 1 row 2 column The corrected data is: 1 0 1

1 0 1 1 1 1

(17)
(18)

IMPLEMENTATION OF CRC POLYNOMIALS

AIM:

To implement the CRC-12, CRC-16, CRC-CCITT in data link layer

LOGIC:

1. let r be the degree of G(x).Append r zero bits to the low-order end of the frame. So it now contains m+r bits and corresponds to the polynomial x2 m(x).

2. divide the bit string corresponding to G(x) into the bit string corresponding to x2 m(x) using modulo-2 division.

3. subtract the remainder from the bit string corresponding to x2 m(x) using modulo-2 sub. The result is the check summed frame to be transmitted. We call it as a polynomial.

PSEUDO CODE:

1. Take the frame as input from the user.

2. Take the user‟s choice of use of the CRC polynomial that he wants to use: CRC-12 = x12+x11+x 3+x 2+x+1

CRC-16 = x16+x15+x 2+1 CRC-CCITT = x16+x 12+x 5+1

3. Depending upon the user‟s choice, append the zeros to the end of the frame and display.

4. Calculate the CRC by performing modulo 2 division.

5. Replace the appended zeros in step 3 by the remainder of the above performed division.

6. This is the transmitted data.

7. At the receiver side, the input string is subjected to modulo 2 division by the same polynomial that was used at the sender side.

8. If the remainder is 0 there is no error otherwise there was an error during transmission.

/* Result with no error */

INPUT:

Enter frame: 1101011011 Enter your choice: 1.CRC 12

2.CRC 16 3.CRC CCITT 1

(19)

OUTPUT:

Frames after appending zeros: 1101011011000000000000 Remainder: 111101001100 Transmitted data: 1101011011111101001100 Received data: 1101011011111101001100 Remainder: 0 No Error /* Result with error */

INPUT: Enter frame: 1101011011 Enter your choice: 1.CRC 12

2.CRC 16 3.CRC CCITT 1

OUTPUT: Frames after appending zeros: 1101011011000000000000 Remainder: 111101001100 Transmitted data: 1101011011111101001100 Received data: 1101011011111101011100 Remainder: 100 Error

(20)

IMPLEMENTATION OF DATA LINK PROTOCOLS

a) UNRESTRICTED SIMPLEX PROTOCOL

b) STOP AND WAIT PROTOCOL

(21)

UNRESTRICTED SIMPLEX PROTOCOL

AIM:

To implement unrestricted simplex protocol that is sender sends the data from the DLL of source machine to the DLL of the destination machine without any sequence no. or acknowledgement.

LOGIC:

In this protocol data are transmitted in one direction only. Both the transmitting and receiving network layers are always ready processing time can be ignored. Infinite buffer the data link layers never damages or losses frames. This is an unrestricted protocol. This protocol is also called as „Utopia‟.

PSEUDO CODE: void sender1(void) { frame s; packet buffer; while(true) { from_network_layer(&buffer); s.info=buffer; to_physical_layer(&s); } }/* end of sender1*/ void receiver1(void) { frame r; event_type event; while(true) { wait_for_event(&event); from_physical_layer(&r); to_network_layer(&r.info); } }/* end of receiver1*/

(22)

INPUT:

Enter the no. of frames: 2 Entered message is hi

The frame is transmitted

Frame has arrivedMessage given to the network layer is „hi‟ Entered Message is

Hai

The frame is transmitted

(23)

SIMPLEX PROTOCOL FOR A NOISY CHANNEL

AIM:

To implement simplex protocol for noisy channel in data link layer

LOGIC:

The same scenario which we have implemented in the simplex stop and wait protocol is implemented in this protocol with the help of timers

PSEUDO CODE: Void sender2(void) { frame s; packet buffer; event_type event; while(true) { from_network_layer(&buffer); s.info=buffer; to_physical_layer(&s); wait_for_event(&event); } } /*end of sender2*/ void receiver2(void) { frame r,s; event_type event; while(true) { wait_for_event(&event); from_physical_layer(&r); to_network_layer(&r.info); to_physical_layer(&s); } } /*end of receiver2*/

(24)

INPUT:

Enter no. of frames 2 Enter the message queue M1=42

OUTPUT:

The frame is transmitted Frame had arrived

Acknowledge to network layer

(25)

STOP AND WAIT PROTOCOL

AIM:

To implement the stop and wait protocol in DLL

LOGIC:

The sender must never transmit a new frame until undone has been fetched from physical layer, then the new one overwrites the old one.

The general solution to this problem is to have the receiver send a little dummy frame to t5he sender which , In effect gives the sender permission to transmit the next frame.

Protocol in which in-effect dummy frame back to the sender which in effect gives the sender permission to transmit the next frame.

Protocols in which sender sends one frame and then waits for acknowledgement before proceeding are called stop and wait protocols.

PSEUDO CODE: void sender3(void) { seq_nr next_frame_to_send; frame s; packet buffer; event_type event; next_frame_to_send=0; from_network_layer(&buffer); while(true) { s.info=buffer; s.seq=next_frame_to_send; to_physical_layer(&s); start_timer(s.seq); wait_for_event(&event); if(event==frame_arrival) { from_network_layer(&buffer); inc(next_frame_to_send); } } } /*end of sender3*/ void receiver3(void) { seq_nr frame_expected;

(26)

event_type event; frame_expected=0; while(true) { wait_for_event(&event); if(event==frame_arrival) { from_physical_layer(&r); } to_physical_layer(&s); } } /*end of receiver3*/ INPUT:

Enter the number of frames: 2 Entered message is:

Hi

OUTPUT:

The frame is transmitted Frame has arrived.

Acknowledge to network layer Message given to the network layer is “hi” Entered message is

Hai

The frame is transmitted Frame has arrived.

Acknowledge to network layer Message given to the network layer is “hai”

(27)

IMPLEMENTATION OF SLIDING WINDOW PROTOCOLS a) ONE BIT SLIDING WINDOW PROTOCOL

b) GO BACK N SLIDING WINDOW PROTOCOL

(28)

ONE BIT SLIDING WINDOW PROTOCOL

AIM:

To achieve flow control in the data link layer at the receivers side efficiently using one bit sliding window protocol.

LOGIC:

1. The starting machine fetches the first packet from it‟s network layer, builds a frame and sent it

2. When this frame arrives the receiving data link layer checks to see if it is duplicate.

3. If the frame is given expected it is passed to the network layer and the receiver window is slid up.

PSEUDO CODE: Void protocol4(void) { seq_nr next_frame_to_send; seq_nr frame_expected; frame r,s; packet buffer; event_type event; next_frame_to_send=0; frame_expected=0; from_network_layer(&buffer); s.info=buffer; s.seq=next_frame_to_send; s.ack=1-frame_expected; to_physical_layer(&s); start_timer(s.seq); while(true) { wait_for_event(&event); if(event==frame_arrival) from_physical_layer(&r); if(r.seq==frame_expected) { to_network_layer(&r.info); inc(next_frame_to_send); } } s.info=buffer; s.seq=next_frame_to_send;

(29)

to_physical_layer(&s); start_timer(s.seq); }/* end of protocol4*/

INPUT:

Enter the no. of frames: 2 Sender

Enter the message : hi Frame is transmitted Receiver

Frame is arrived

Message given to the network layer is „hi‟ Sender

Enter the message: hai Sender

Frame is transmitted Receiver

Frame is arrived

(30)

GO BACK N SLIDING WINDOW PROTOCOL

AIM:

Implementation of the Go Back N sliding window protocol

LOGIC:

Two basic approaches are available foe dealing with errors in the presence of the pipelining. One way, called go back n, is for the receiver simply to discard all subsequent frames, sending no acknowledgements for the discarded frames. This strategy corresponds to a receive window of size 1. In other words, the data link layer refuses to accept any frame except the next one it must give to the network layer. If the sender‟s window fills up before the timer runs out, the pipeline will begin to empty. Eventually, the sender will time out and retransmit all unacknowledged frames in order, starting with the damaged or lost one. This approach can waste a lot of bandwidth if the error rate is high.

We see go back n for the case in which the receiver‟s window is large. Frames 0 and 1 are correctly received and acknowledged. Frame 2 however, is damaged or lost. The sender unaware of this problem, continues to send frames until the timer for frame 2 expires. Then it backs up frame 2 and starts all over with it, sending 2, 3, 4, etc all over again.

PSEUDO CODE:

Void protocol5(void) {

MAX3SEQ > 1; used for outbound stream oldest frame as yet unacknowledged next frame expected on inbound stream initialize scratch variable

buffers for the outbound stream while(true)

{

four possibilities: see event_type above the network layer has a packet to send fetch new packet

expand the sender‟s window transmit the frame

advance sender‟s upper window edge a data or control frame has arrived get incoming frame from physical layer }

(31)

INPUT AND OUTPUT:

Enter the no. of frames: 2 Enter the msg: ab

Transmission in one direction M1=80

Error in transmission re-send all the frames Enter the msg: df

Transmission in one direction M1=86

Frame arrived

Acknowledgement to network layer Transmission in opposite direction M1=86

Enter thr msg: df

Transmission in one direction M1=93

Frame arrived

Acknowledgement to network layer Transmission in opposite direction M1=93

(32)

SELECTIVE REPEAT SLIDING WINDOW PROTOCOL

AIM:

Implementation of Selective repeat sliding window protocol

LOGIC:

In this protocol, both sender and receiver maintain a window of acceptable sequence numbers. The sender‟s window size starts out at 0 and grows to some predefined maximum, MAX3SEQ. the receiver‟s window, in contrast, is always fixed in size and equal to MAX3SEQ. the receiver has a buffer reserved for each sequence number within its fixed window. Associated with each buffer is a bit(arrived) telling whether the buffer is full or empty. Whenever a frame arrives, it‟s se4quence number is checkerd by the function between() to see if it falls within the window. If so and if it has not already been received , it is accepted and stored. This action is taken without regard to whether or not it contains the next packet expected bt the network layer. Of course it must be kept within the datalink layer and not passed to the network layer until all the lower numbered frames have already been delivered to the network layer In the correct order.

PSEUDO CODE

Void protocol6(void) {

initialize lower edge of the sender‟s window initialize upper edge of the sender‟s window+1 initialize lower edge of the receiver‟s window initialize lower edge of the receiver‟s window+1 initialize index into buffer pool

initialize scratch variable

buffers for the outbound stream buffers for the inbound stream inbound bit map

how many output buffers currently used initialize

next ack expected on the inbound stream number of next outgoing frame

initially no packets are buffered while(true)

{

accept,save, and transmit a new frame expand the window

fetch new packet transmit the frame

advance upper window edge a data or control frame has arrived

(33)

damaged frame we timed out

ack timer expired, send ack }

} /*end of protocol6*/

INPUT:

Maximum sequence number and the frames are given as input to this program.

OUTPUT:

Whether the transmitted frames are received or not is obtained as output of this program.

(34)

IMPLEMENTATION OF ROUTING ALGORITHMS

a) DIJKSTRA’S ALGORITHM

b) DISTANCE VECTOR ROUTING

c) HIREARCHICAL ROUTING

d) BROADCAST ALGORITHM

(35)

TO COMPUTE SHORTEST PATH USING DIJKSTRA’S

ALGORITHM

AIM:

To implement shortest path in a subnet using dijkstra‟s algorithm from a given node

LOGIC:

A subnet with number of paths and infinite node is taken and proceeded As algorithm proceeds the labels change with better values and shortest path is found

PSEUDO CODE:

1. start. 2. total=0,k=0

3. read the number of nodes 4. read the number of edges.

5. repeat step 6 for i=1 to 10 in steps of 1 6. repeat step 6.1 for j=1 to 10 in steps of 1 dist[i][j]=-1

7. read the distance

8. repeat step 9 for i=1 to e in steps of 1 9. display i

repeat for j=0 to 2 in steps of 1 read a[i][j]

read dist(a[i][j])(a[i][1]) 10. read the sorce I,e,s 11. read the destination i,e,d 12. x=s

13. repeat for l=0 to e in steps of 1 14. i=s

repeat for j=1 to n in steps of 1 if (dist[i][j]!=-1) then if dist[i][j]<min then min=dist[i][j] b=j s=b total=total+min min=1000 path[k++]=b if b==d then display x

repeat for i=0 to k in steps of 1 display path[i]

(36)

15. read the choice

16. if ch==y then goto step 2 17. stop.

INPUT:

We first enter the file name as pa.txt and we enter the nodes as 4 Then the distance matrix is 9

0 2 5 0

2 0 3 6

5 3 0 4

0 6 4 6

which is in the file pa.txt

we enter the source node as 1 enter the destination node 4

OUTPUT:

(37)

DISTANCE VECTOR ROUTING

AIM:

To obtain routing table of desired node with new weight along with the predefined weights of a subnet

LOGIC:

The program adds the respective new weights of the neighbor of the desired node to the predefined weights of the node in the subnet and chooses the node with least weight and prints the weight and respective neighbor of node

PSEUDO CODE:

1. start

2. print „enter the number of nodes 3. print „enter the adjacency matrix 4. read the matrixinto dist[i][j]

5. print „enter the node for which routing table to be constructed 6. read into str

7. print the adjacent vertices are 8. print from adj[c]

9. read the delay time

10. constuct the routing table by min=delay[j]+route[i][j] path=adj[j] 11. printf the min->path

12. stop

INPUT:

Enter the router for which you want routing table:A

Enter new time delays for neighboring routers: 6 1 9 19 26 2

OUTPUT:

Ffor A, routing table is

time delay router

6 B 1 B 9 F 19 B 26 F 2 F

(38)

IMPLEMENTATION OF HIERARCHIAL ROUTING

ALGORITHM

PROGRAM DEFINITION:

This program deals with the implementation of Hierarchical routing algorithm.

PROGRAM DESCRIPTION:

In this program, we use only one function namely main( ) and we do everything here only. We enter route no and the no of entries in the routing table and we enter each entry, destination router, line and no of hops and we pring full routing table and hierarchial routing table.

ALGORITHM

1. Start.

2. Print enter the router name. 3. read the router name

4. Print enter number of entries. 5. Read number of entries.

6. Repeat through steps 14 for l0 upto i<n in, steps of 1. 7. Print entry.

8. read i;

9. Print destination router. 10. Read table[i] dest. 11. print line

12. Read table[i].line. 13. print hops

14. Read table[i].hps.

15. Print full routing table for route.

16. Repeat through step 17 for u0 upto i<n in steps of 1. 17. Print table[i].dest,table[i].line,table[i].hps.

18. Print heirarchial routing table for route.

19. Repeat through step 21.6 for i0 upto i<n in steps of 1.

20. If (name[0]=table[i].dest[0]). Then print table[i]==table[i].dest[0]).then print tab[i].line,table[i].hps).

21. Else repeat through steps-21.6. 21.1. min9999 21.2. pos0,k0. 21.3. repeat through 21.4. if(table[j].dest[0]==table[i].dest[0] then 21.4.1. kk+1. 21.4.2, if(table[j].hps<min) then. 21.4.2.1. mintable[j].hps

(39)

21.5. print table[pos].dest[0],table[pos].line,table[pos].hps. 21.6. i i+k-1.

22. getch(); 23. stop.

TEST DATA

Enter the router name :1a. Enter the number of entries :3. Entry : 0. Destination router : 1b. Line : 1a. Number of hops : 1. Entry : 1. Dtestination router : 1d. Line : 1a. Number of hops : 2. Entry : 2. Destination router : 2c. Line : 1b. Number of hops : 4.

Full routing table for router 1a. Dest Line Hops 1b 1a 1 1d 1a 2 2c 1b 4

(40)

BROAD CAST ALGORITHM

AIM:

Sending a packet to all destinations simultaneously using broadcast algorithm

LOGIC:

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 .

PSEUDO CODE:

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.

INPUT:

1. We have entered the number of nodes and adjacency matrix for nodes. 2. We have entered the source for broadcasting.

OUTPUT:

(41)

CONGESTION ALGORITHMS

a) TOKEN BUCKET ALGORITHM

b) LEAKY BUCKET ALGORITHM

(42)

TOKEN BUCKET ALGORITHM

AIM:

To implement the Token Bucket Congestion Algorithm.

DESCRIPTION:

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.

(43)

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

(44)

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.

LOGIC:

1.The addresses are classified as per the rules.

2. The input from the user is taken in the form of address.

3. The program compares the first 8 bits of the address and classifies it according to the respective class.

INPUT:

Enter the address:127.254.254.254

OUTPUT:

The address is a class A Address.

INPUT:

Enter the address:192.234.254.224

OUTPUT:

The address is a class C Address.

(45)

ENCRYPTION ALGORITHMS

a) SUBSTITUTION CIPHERS

b) TRANSPOSITION CIPHERS

(46)

SUBSTITUTION CIPHER

PROGRAM DEFINITION:

To write a program for substitution cipher

PROGRAM DESCRIPTION:

In this program, we use two functions namely sub(), trans() function. In the substitution function we substitute each letter by some other letter. In the transposition function we exchange the letters and by decrypted text. We print the original text again.

LOGIC:

1. The string to be encrypted is taken from the user as input.

2. The characters of the string are substituted by other characters in this program.

3. While substituting, a key is maintained throughout the substitution.

INPUT:

Enter the string RGMCET

OUTPUT:

(47)

TRANSPOSITION CIPHER

PROGRAM DEFINITION:

To write a program for substitution cipher

PROGRAM DESCRIPTION:

In this encryption technique, the characters of the string are not substituted but are rearranged among themselves. A definite pattern is followed for rearranging the characters and this pattern is followed throughout the transposition.

LOGIC:

1. The string to be encrypted is taken from the user as the input. 2. A key word is written out .

3. All the characters of the input string are laid under each character of the key in the form of a matrix.

4. Now the encrypted string is obtained as follows:

a. Transmit all the characters under the each alphabet of the key in the alphabetical order.

b. The resultant string thus transmitted is the encrypted string. Eg:

Key: RGMCET

String: all students are good

R G M C E T

a l l s t u

d e n t s a

r e g o o d

The transmitted string is: stotsoleelngadruad.

INPUT:

Enter the string to be encrypted: all students are good

OUTPUT:

The transmitted string is stotsoleelngadruad

(48)

DATA ENCRYPTION ALGORITHM

AIM:

To encrypt and decrypt the given text using data encryption algorithm.

LOGIC:

1. DES consists of 2 permutation steps in which all 64 bits are permuted with 16 identical rounds of operation in between.

2. The operation of each round is identical, taking the output of previous round as input.

METHOD:

1. A 64 bit plain text block is given as input. 2. This block is subjected to Initial Permutation.

3. At this stage the 64 bit key is used along with the above obtained data to produce an intermediate result.

4. The above step is performed for 16 rounds.

5. In each round , the following steps are performed:

a. Expansion/permutation(E Table) of right most 32 bits of data. b. XOR of above data with the key.

c. Subject to S Box. d. Permutation.

e. XOR of the above block with left 32 bits of data. 6. Then the data is swapped in 32 bit blocks.

7. After the swapping, inverse initial permutation is performed on the swapped block and thus the final encrypted block is obtained.

INPUT:

Enter a 10 bit key:1010101010 Enter the 8 bit plain text:11111111

LS2=10110 LS-2=00111

K1=1110011 K2=01011111

Concat=1110 e=01000100

We have entered 10 bit key

Next, we have entered the 8 bit plain text.

OUTPUT:

(49)

IMPLEMENTATION OF SERVERS

a) DATE SERVER

b) CHAT SYSTEM

c) ECHO SERVER

(50)

DATE SERVER

PROGRAM DEFINITION:

This is the program that links the server and client and sends the data from server to the client when client connects.

PROGRAM DESCRIPTION:

Program, when client connects to the server the server its data to the client and also indication that the connection has been established.

ALGORITHMS:

Server program:

1. start

2. open the socket of client/server by serversocket ss=new serversocket(888);

3. print connection established. 4. enter date into d by

Date d= new Date(); 5. send it to client.

Client program

1. open socket using

Socket s= new socket(InetAddress.getLocalHost(),888); 2. print client started.

3. read date from socket 4. else print unable to connect 5. stop.

TEST DATA:

[ Run both the program ] Enter message : Hai

From server : connection established 22.03.06.

(51)

CHAT SYSTEM

PROGRAM DEFINITION:

This is the program to connect both server and client and establishing connection.

PROGRAM DESCRIPTION:

Program initially connects server to client and passes information form from one system to another and viceversa that by creating / establishing connection.

ALGORITHMS:

Server Process:

1. start.

2. create a class chats 3. open a socket by

server Socket ss=new ServerSocket(999); 4. print “server started”

5. accept the input from the client 6. replay for the client by function

pw=new PrintWriter(s.getoutputstream()); 7. close the socket.

Client Process:

1. create a class chatc 2. open socket by

Socket s=new socket(InetAddress.getLocalHost(),999); 3. print “client started”

4. enter message 5. send to server 6. If message=bye 7. break the connection 8. close the socket 9. stop.

TEST DATA:

[ Run both the program ] Enter message : hai From Server : hai At Server : hai

Enter message at Client : krishna At Server : krishna

(52)

At Client : bye

ECHO SERVER

PROGRAM DEFITION:

This program is developed to reply for clients action by establishing connection.

PROGRAM DESCRIPTION:

Initially program connects the server to client and what ever the information placed on the server by the client was read out by the server and same was sent to the client. This causes the echoing system.

CLIENT PROGRAM:

PROGRAM DEFINITON:

This program is developed to send message for server when connection established.

PROGRAM DESCRIPTION:

Initially program connects client to the server and what ever information placed on the server by client was sent back to client. This causes the echoing system.

Algorithm for server program

1. start

2. create a class echos

3. create a socket by serversocket ss=new serversocket(999) 4. print server started

5. accept the input from client by function socket s=ss.accept(); 6. print „connection established

7. echo it to the client by using printwriter pw=new printwriter (s.getOutputStream());

8. close the socket

Algorithm for client program

1. start

2. create a class achoc

3. create/open socket by socket s=new socket(InetAddress.getLocalHost(),999); 4. print „client started‟

5. enter message

6. it was sent back by server

7. if message=‟bye‟ it breaks the connection 8. cloase the socket

(53)

TEST DATA:

[Run both the client and server programs] Enter message: Krishna

From server: Krishna Enter message: Rangaiah From server: Rangaiah Enter: bye

References

Related documents

OSI is a reference model that describes the functions of a telecommunication or networking system while TCPIP is a disease of communication protocols used to interconnect

Introduction to the communication protocols, The OSI reference model, Format of the information, The OSI model: Physical Level (level 1), Line Level (level 2), Network Level (level

Trivial hypertext transfer protocol may exist, osi model network, then tearing down from users connected physically transmitting more reliable network does osi layer protocols

The pdf request and differences between one process is required to reach their adoption in each layer is primarily used at what is composed of osi model and protocols in each layer

Data link layer The second lowest layer of the seven-layer Open Systems Interconnection (OSI) model of computer networking. DDoS distributed denial

Physical layer of application layer may be responsible for example, on all osi model is just that are examples of data between networks?. New service data center, or udp header

When identifying which is remarkably flexible, many network layer include https can reliably and forwarding data has succeeded a particular route network routes that these

Of particular interest is the relationship between the Open Systems Interconnection (OSI) model and protocols. It is stressed that the OSI reference model or any