JNTU B.tech Computer Networks Lab Manual All Programs (1)
Short Description
Download JNTU B.tech Computer Networks Lab Manual All Programs (1)...
Description
COMPUTER NETWORKS LAB MANUAL
Prepared by
Department of Computer Science & Engineering RAO & NAIDU ENGINEERING COLLEGE
Computer Networks Lab Manual
1 / 53
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 lowlevel, 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.
Computer Networks Lab Manual
2 / 53
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 #include 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:
Computer Networks Lab Manual
3 / 53
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 , 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 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; };
Computer Networks Lab Manual
4 / 53
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; }
Computer Networks Lab Manual
5 / 53
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 c) ECHO SERVER
Computer Networks Lab Manual
6 / 53
SIMULAION OF OSI MODEL
Computer Networks Lab Manual
7 / 53
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 MESSAGE ENTERED INTO PHYSICAL LAYER AND TRANSMITTED.
Computer Networks Lab Manual
8 / 53
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 APPLICATION LAYER: AH hai
Computer Networks Lab Manual
9 / 53
IMPLEMTATION OF DATA LINK FRAMING METHODS b) CHARACTER COUNT c) BIT STUFFING AND DE STUFFING d) CHARACTER STUFFING AND DE STUFFING
Computer Networks Lab Manual
10 / 53
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: frame 1: 1234 frame 2: 678
Computer Networks Lab Manual
11 / 53
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: De stuffed data is: 11111110101
Computer Networks Lab Manual
12 / 53
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
Computer Networks Lab Manual
13 / 53
PARITY CHECK a)
SINGLE DIMENSIONAL DATA
b)
MULTI DIMENSIONAL DATA
Computer Networks Lab Manual
14 / 53
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
Computer Networks Lab Manual
15 / 53
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: 33 enter data: 101 101 111 Horizontal parity: 001 Vertical parity: 111 Enter received data: 111 101 111 Horizontal parity: 101 Vertical parity: 101 error is at 1 row 2 column The corrected data is: 101 101 111
Computer Networks Lab Manual
16 / 53
CYCLIC REDUNDANCY CHECH (CRC)
Computer Networks Lab Manual
17 / 53
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
Computer Networks Lab Manual
18 / 53
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
Computer Networks Lab Manual
19 / 53
IMPLEMENTATION OF DATA LINK PROTOCOLS a) UNRESTRICTED SIMPLEX PROTOCOL b) STOP AND WAIT PROTOCOL c) NOISY CHANNEL
Computer Networks Lab Manual
20 / 53
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*/
Computer Networks Lab Manual
21 / 53
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 Frame has arrivedMessage given to the network layer is „hai‟
Computer Networks Lab Manual
22 / 53
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*/
Computer Networks Lab Manual
23 / 53
INPUT: Enter no. of frames 2 Enter the message queue M1=42 OUTPUT: The frame is transmitted Frame had arrived Acknowledge to network layer Message given to the network layer is queue
Computer Networks Lab Manual
24 / 53
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; frame s,r;
Computer Networks Lab Manual
25 / 53
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”
Computer Networks Lab Manual
26 / 53
IMPLEMENTATION OF SLIDING WINDOW PROTOCOLS a) ONE BIT SLIDING WINDOW PROTOCOL b) GO BACK N SLIDING WINDOW PROTOCOL c)SELECTIVE REPEAT SLIDING WINDOW PROTOCOL
Computer Networks Lab Manual
27 / 53
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; s.ack=1-frame_expected;
Computer Networks Lab Manual
28 / 53
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 Message given to network layer is „hai‟
Computer Networks Lab Manual
29 / 53
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 } } /*end of protocol5*/
Computer Networks Lab Manual
30 / 53
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
Computer Networks Lab Manual
31 / 53
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 fetch incoming frame from the physical layer advance lower edge of sender‟s window
Computer Networks Lab Manual
32 / 53
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.
Computer Networks Lab Manual
33 / 53
IMPLEMENTATION OF ROUTING ALGORITHMS a) DIJKSTRA’S ALGORITHM b) DISTANCE VECTOR ROUTING c) HIREARCHICAL ROUTING d) BROADCAST ALGORITHM
Computer Networks Lab Manual
34 / 53
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]2->4
Computer Networks Lab Manual
36 / 53
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. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
start print „enter the number of nodes print „enter the adjacency matrix read the matrixinto dist[i][j] print „enter the node for which routing table to be constructed read into str print the adjacent vertices are print from adj[c] read the delay time constuct the routing table by min=delay[j]+route[i][j] path=adj[j] printf the min->path 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 6 1 9 19 26 2
Computer Networks Lab Manual
router B B F B F F
37 / 53
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 l0 upto i
View more...
Comments