This action might not be possible to undo. Are you sure you want to continue?

INSTITUTE OF TECHNOLOGY, Bangalore – 560 085 Session: Aug - Dec 2009

CCN LABORATORY MANUAL VII SEMESTER TELECOMMUNICATION ENGG

**CONTENTS CCN Programming using C/C++ (3 Lab Sessions)
**

1. Simulate bit stuffing & de-stuffing using HDLC. 2. Simulate character stuffing & de-stuffing using HDLC 3. a. Encryption of a given message Using Substitution Method.

b. Decryption of a given message Using Substitution Method. 4. a. Encryption of a given message Using Transposition Method. b. Decryption of a given message Using Transposition Method.

5. Compute Polynomial Code Checksum for CRC-CCITT

6. Simulate the Shortest Path Algorithm 7. Find Minimum Spanning Tree of a Subnet

**CCN Experiments using Hardware (1 Lab Session)
**

8. Asynchronous and Synchronous Communication using RS232 / Optical

Fiber / Twisted Pair / RJ45.

CCN Lab Manual

9. Demonstrate the use of fork function to create two processes and

**communicate between them.
**

10. Demonstrate communication between two PCs using socket function.

11.Demonstrate the operations of rlogin and Telnet. 12.Demonstrate the operations of ftp and Mailbox.

Staff-in-Charge: Sushma Rawal

CCN Programming using C/C++ 1. Simulate bit stuffing & de-stuffing using HDLC Digital communication has its advantages of speed, reliability, etc but with it comes a problem of control signals. In analog communication the modulation technique used can be used to generate control signals. Like in FDM 3 frequencies can be used: one frequency for a low, another one for a High and finally a third frequency for a control signal. But this isn’t possible in Digital communication. Bit patterns or Bytes can be reserved for control signals. These control signals cannot be present in normal data. This can be achieved for ASCII text or if a few bit patterns are used as data. But when the whole set of bit patterns or ASCII values are used the special control signals cannot be present in data and if present should not be interpreted as control signals but be interpreted as data. This is the reason we use Stuffing. Stuffing is the process of adding redundant information or increasing the amount of data transmitted in order to accommodate control signals. This can be done in 2 ways: Bit Stuffing: This is used when a bit oriented communication system is used. Let us consider the control signals of frame start/end. We give them a representation of 0111 1110. So now if this is present in the data we are transmitting we change this patter so that it no longer matches the control signal of frame start/end. Each time we see 5 ones at the transmitter we append a 0 instantly so that 6 ones can never exist. An argument can be raised about the fact why should we add the zero after 5 ones if the 6th bit

2/28

The reason is simple enough . 01111101 can now be interpreted as 0111 1110 (assuming 0 is a stuffed 0) 0111 1101 (assuming 0 is data) So once it is settled that every 5 ones has a zero following it irrespective of the next bit being a 0 or a 1 lets see what the receiver has to do.the receiver cannot differentiate between that 0 which is a data and a stuffed 0. Add start of frame to output sequence 3. HDLC frame is as shown. Append bit to output sequence b. Is bit a 1? Yes: Increment count If count is 5.CCN Lab Manual was a 0 and not a one. The Checksum field is a minor variation of the CRC code using CRC-CCITT as the generator. For example. The Data field may contain arbitrary information. Algorithm for Bit Stuffing 1. The Control field is used for sequence numbers and acknowledgements and other purposes. HDLC Frame The high level data link control protocol is a bit oriented protocol which uses bit stuffing for data transparency. For every bit in input a. Frames are delimited by 0111 1110 and this sequence is not allowed in the data field. Input data sequence 2. Add stop of frame bits to output sequence Algorithm for Bit Destuffing: 3/28 . The receiver keeps a count of the ones and each time it receives 5 ones it discards the next bit if it is a 0 bit which is the stuffed 0 bit and knows this isn’t a control signal but if the bit after 5 ones is also a 1 it knows its a frame end/start. append 0 to output sequence and reset count No: Set count to 0 4.

b. else counter=0. a.h> void main() { /* Array is already initialised to 01111110 which is the flag byte. If count is 5. Remove start of frame from sequence. 2. 3.h> # include <conio. For every bit in input. remove next bit (which is 0) and reset count."01111110"). Hence a counter 'i' /* has to point to the eight location in the same array */ char ch. 4. Remove end of frame bits from sequence. /* Only the data portion of the frame is inputted */ printf("Enter the original data stream for bit stuffing : \n"). while((ch=getche())!='\r') { if (ch=='1') ++counter. Input the stuffed sequence.k. array[i++]=ch. No: Set count to 0. int counter=0.j. Append bit to output sequence. if (counter==5) /* If 5 ones are encountered append a zero */ { array[i++]='0'. } } strcat(array.recd_array[50].i=8. /* Appending the flag byte at the end of the stream */ /* i now has the value of the flag byte length + data stream length */ 4/28 . clrscr(). Is bit a 1? Yes: Increment count. counter=0.CCN Lab Manual 1. array[50]={"01111110"}. /* Program to simulate bit stuffing where the flag byte is 01111110 */ # include <stdio.

for (j=8. else counter=0. } } for (j=0.j<i+8.array[j]). for (j=0. printf("\nThe destuffed data stream is : \n").recd_array[j]).k=0.++j) printf("%c". delete the following zero */ { ++j. /* Destuffing */ counter=0.j<i+8.++j) { if (array[j]=='1') ++counter. } Output: Enter the original data stream for bit stuffing : 011011111111110010 The stuffed data stream is : 011111100110111110111110001001111110 The destuffed data stream is : 011011111111110010 2. Simulate character stuffing & de-stuffing using HDLC Bit stuffing seems to be a foolproof plan but sometimes the communication system cannot handle bits but can only manipulate bytes (8 bits). recd_array[k++]=array[j]. /* Printing the final destuffed array */ getch().CCN Lab Manual printf("\nThe stuffed data stream is : \n"). else if (counter==5 && array[j+1]=='0') /* If five ones appear. In these 5/28 . counter=0.++j) printf("%c". if (counter==6) /* End if six ones are encountered */ break.j<=k-strlen("01111110").

3. SO if we receive a ETX or a STX and the previous ASCII value inst DLE we know it’s a frame start/end. Similar is the case for STX. Remove start of frame from sequence (DLE STX). 4. No: Continue. Append character to output sequence b. For every character in input. a. The end of text will now become as data as the receiver will get DLE ETX. So now even DLE is stuffed. /* Program to demonstrate character stuffing */ # include <stdio. STX. Add start of frame to output sequence (DLE STX) 3. Input data sequence 2. The principle remains the same STX (ASCII 02) denotes a start of data and ETX (ASCII 03) the end of text. To make sure this happens we use another ASCII value called DLE (ASCII 16). 2. The main control signals are ETX (End text). Consider the case when DLE was the last data byte. Incase ETX or the byte 03 happens to be present in data it should be treated as data and not end of text. and DLE (Data Link Escape). Add stop of frame chars to output sequence Algorithm for Character Destuffing: 1.h> # include <conio. Input stuffed sequence. Other control signals are also present like SOH (start of header).h> # define DLE 16 6/28 . For every character in input a. Each time we see a STX in data we make it DLE STX and an ETX is made into DLE ETX. So each time transmitter sees DLE it makes it DLE DLE. STX (Start text). DLE. Algorithm for Character Stuffing 1. b. EOT (End of transmission) etc but we will restrict the discussion to ETX. Append character to output sequence.CCN Lab Manual cases we assume an ASCII set. Is character DLE? Yes: Add DLE to output sequence 3. Is character DLE? Yes: Remove next DLE from input sequence. Remove stop of frame character to output sequence (DLE ETX).

for (j=2.ch). } array[i++]=DLE. else printf("%c ". } else if (ch==STX) printf("STX "). printf("\nThe stuffed stream is \n").STX}. for (j=0. /* the frame delimiter bytes initially */ clrscr().array[j]). array[i++]=ETX.++j) { if (array[j]==DLE) printf("DLE "). Ctrl+P>DLE) : \n"). /* Initialise the array to have */ int i=2. } else if (array[j]==STX) 7/28 .j.j<i. array[i++]=ch. else if (ch==ETX) printf("ETX ").CCN Lab Manual # define STX 2 # define ETX 3 void main() { char ch. ++j. else if (array[j]==ETX) printf("ETX "). /* Inputting the data stream alone */ printf("Enter the data stream (Ctrl+B->STX. while ((ch=getch())!='\r') { if (ch==DLE) /* Checking for DLE */ { array[i++]=DLE. else if (array[j]==STX) printf("STX "). else printf("%c ". char array[100]={DLE. Ctrl+C->ETX.++j) { if (array[j]==DLE) /* Checking for DLE */ { printf("DLE "). printf("DLE "). } /* Destuffing of character stream */ printf("\nThe destuffed data stream is : \n").j<i-2.

Ctrl+C->ETX. Ctrl+P->DLE) : A DLE B The stuffed stream is DLE STX A DLE DLE B DLE ETX The destuffed data stream is : A DLE B 8/28 . } getch(). } Output: Enter the data stream (Ctrl+B->STX. else printf("%c ".CCN Lab Manual printf("STX "). else if (array[j]==ETX) printf("ETX ").array[j]).

say the 26 letters for simplicity. inject his own messages. Similarly. For the key above. However. with the key being the 26-letter string corresponding to the full alphabet. P=DK(C) represents decryption of C to get the plaintext again. each letter or group of letters is replaced by another letter or group of letters to disguise it. A way to do this is to have each of the symbols in the plaintext. The art of devising ciphers (cryptography) and breaking them (cryptanalysis) is collectively known as cryptology. known as plaintext. The art of breaking ciphers is called cryptanalysis. Plaintext P=DK(EK(P)) Substitution Ciphers In a substitution cipher. he does not know what the decryption key is and so cannot decrypt the ciphertext easily. Encryption methods are historically divided into two categories: substitution ciphers and transposition ciphers. map onto some other letter. Plaintext-P. It then follows that DK(EK(P)) = P Fundamental rule of cryptography is that one must assume that the cryptoanalyst knows the general method of encryption used. is then transmitted. We assume that the enemy or intruder. Plaintext: a b c d e f g h i j k l m n o p q r s t u v w x y z Ciphertext: Q W E R T Y U I O P A S D F G H K L Z X C V B N M This general system is called a mono-alphabetic substitution. Decryption key-Dk. are transformed by a function that is parameterized by a key. Encryption Method Cipher C=Ek(P ) Decryption Method Encryption key-Ek. Sometimes the intruder cannot only listen to the communication channel (passive intruder) but can also record messages and play them later. The output of the encryption process.CCN Lab Manual 3a. ciphertext and keys. the messages to be encrypted. We will use C=EK(P) to mean that the encryption of the plaintext P using key K gives the ciphertext C. or modify legitimate messages before they get to the receiver (active intruder). the plaintext attack would be transformed into the ciphertext QZZQEA. hears and accurately copies down the complete ciphertext. It will often be useful to have a notation for relating plaintext. unlike the intended recipient. Algorithm for Encryption by Substitution Method 9/28 . For example. known as ciphertext. often by messenger or radio.Encryption of a given message by Substitution Method In cryptography.

3. so now '0' will be at 26 or sequence[26]*/ 10/28 .len.. For every character of data a.h> # include<ctype.i<len. so index sequence on char-48 + 26. else if(data[i]>='0' && data[i]<='9') /*numbers are present at an offset of 26. /*input data*/ char encoded[100]. If data is between 'a' and 'z' set encoded data to uppercase character from key b.h> void main() { const char sequence[36]="qwertyuiopasdfghjklzxcvbnm4852630791". char data[100]. Read data to be encoded 2. else if(data[i]>='A' && data[i]<='Z') /*if uppercase letter subtract 65 so that 'A' becomes 0 encoded data is seqence['A'-65]*/ encoded[i]=sequence[(data[i]-65)].++i) { if(data[i]>='a' && data[i]<='z') /*if small letter subtract from 97 so 'a' becomes 0 and convert sequence[0] to uppercase for 'a'*/ encoded[i]=toupper(sequence[(data[i]-97)]).CCN Lab Manual 1.. If data is between 'A' and 'Z' set encoded data to lowercase character from key c. else copy data into encoded data’s array. gets(data). for(i=0. If data between '0' and'9' set encoded data to digit from key d. /*encoded data*/ int i. Print encoded data.h> # include<stdio.. printf("\nEnter data to be encoded:"). /* Encryption by Substitution method */ /* Program to encrypt given data even numbers sequence is a key on which you change data change all small letters to big and vice versa*/ # include<string. len=strlen(data).

For every character of data a.i<len.j<36 && !present.++i) /*for every element of input data*/ { for(j=0. len=strlen(data).encoded). gets(data). Print decoded data. Read encrypted data 2.present=0. else encoded[i]=data[i].len. (ii) If not present copy data into decoded data’s array.h> void main() { char sequence[36]="qwertyuiopasdfghjklzxcvbnm4852630791". for(i=0. printf("Encoded string : %s".CCN Lab Manual encoded[i]=sequence[(data[i]-48)+26].Decryption of a given message by Substitution Method Algorithm for Decryption by Substitution Method 1. /* Decryption by Substitution method */ /* Find the given character in key find the location and add that to 'a' or 'A' or '0' as per requirements */ # include<stdio. Scan through key to see if data is present (i) If present get index of character add it to 'a' if data is uppercase else 'A' if it is in lowercase else '0' if it is a digit. /*decoded data*/ int i. 3.h> # include<string. } Output: Enter data to be encoded: Hello World! Encoded string : iTSSG vGKSR! 3b.++j) /*compare with sequence*/ 11/28 .h> # include<ctype. /*input data*/ char decoded[100]. char data[100]. printf("\nEnter data:").j. /*else send punctuation marks or special chars normally*/ } encoded[len]='\0'.

/*is present is 1 make it 0 for next time*/ } decoded[len]='\0'.Encryption of a given message by Transposition Method Transposition Ciphers Substitution ciphers preserve the order of the plaintext symbols but disguise them. /*a lower case letter is converted to upper case*/ else /*a digit is encountered*/ decoded[i]='0'+(j-26).CCN Lab Manual { if(sequence[j]==tolower(data[i])) /*if data matches*/ /*numbers are not changed by tolower/toupper*/ { if(isupper(data[i])) /*numbers return false for this only upper case letters will return true*/ decoded[i]='a'+j. Transposition ciphers. column 1 being under the 12/28 . in contrast. The cipher is keyed by a word or phrase not containing any repeated letters. /*set flag saying digit is present*/ } } if(!present) decoded[i]=data[i]. } Output: Enter data: iTSSG vGKSR! Decoded string is : Hello World! 4a. The purpose of the key is to number the columns. /*digits are at an offset of 26*/ present=1. reorder the letters but do not disguise them. The figure below depicts a common transposition cipher. In this example. /*an upper case letter is converted to lower case*/ else if(islower(data[i])) decoded[i]='A'+j.decoded). MEGABUCK is the key. printf("\nDecoded string is : %s". the columnar transposition. /*assign normal data*/ else present=0.

Get data to be decoded. Jump back to 5 till all columns aren’t done /* Encryption by Transposition method */ # include<string. print the data under this letter c.e.e. The plain text is written horizontally. starting with the column whose key letter is the lowest.' to make last row complete 5. The ciphertext is read out by columns. 3. in rows. Get sequence of characters in Cipher i. For every column of MEGABUCK a.CCN Lab Manual letter closet to the start of the alphabet and so on. MEGABUCK 2. char cipher[8][20]. Send data under this letter i. Plain text : pleasetransferonemilliondollarstomyswissbankaccountsixtwotwo MEGABUCK 74512836 pleasetr ansferon emillion dollarst omyswiss bankacco untsixtw otwoabcd Ciphertext: AFLLSKSOSELAWAIATOOSSCTCLNMOMANTESILYNTWRNNT SOWDPAEDOBUOERIRICXB Algorithm for Encryption by Transposition Method 1. Add '. /*holds MEGABUCK in alphabetical weights ie 13/28 . char wrd[]="MEGABUCK".h> void main() { char data[100]. Find next column to send using sequence b.h> # include<stdio. Arrange data horizontally under MEGABUCK 4. /*cipher arranges characters under megabuck*/ int seq[8].

CCN Lab Manual MEGABUCK 6 3 4 0 1 7 2 5*/ int i. /*find index of value to print first under A i.++i) { cnt=0.e.++j) /*till last char fill with '. 0 so as i=0 find which seq[c] is 0 print that next we search for i=2 or for 2 in seq[c] this is printed out and so on*/ 14/28 .e. for(j=0.i<strlen(wrd)..j<strlen(wrd).c<strlen(wrd).3.1.c. cnt=strlen(data).++i) { for(c=0. changing by 1 at every 8th character */ cipher[i%strlen(wrd)][i/strlen(wrd)]=data[i].. /*to get 63401725*/ /*compare each character of word with every other char and keep count of number of characters is bigger than. /* Arrange data under megabuck in order */ for(i=0. A will be greater than 0 characters B will be greater than 1 character i. i.j..++c) if(seq[c]==i) break.2. if(i%strlen(wrd)!=0) /*if last line is not full*/ { for(j=i%strlen(wrd). } } printf("\nEncrypted data : \n"). ++cnt. for(i=0. changes from 0-7 and back 0-7 as i goes from 0 to cnt-1 resetting to 0 at very 8th char i/strlen(wrd) will go as 0.cnt.*/ for(i=0.++j) if(wrd[i]>wrd[j]) ++cnt.e. seq[i]=cnt.gets(data).'*/ { cipher[j][i/strlen(wrd)]='. } printf("\nEnter data:").j<strlen(wrd).i<cnt. A so 1 and so on.e.++i) /* i%strlen(wrd) will correspond to column number i.i<strlen(wrd).'.4.

Do 4-5 for all characters of MEGABUCK in alphabetical order. Get sequence of characters in word i. /* Decryption by Transposition method */ # include<stdio. } } Output: Enter data: PLEASE TRANSFER ONE MILLION DOLLARS TO MY SWISS BANK ACCOUNT SIX TWO TWO Encrypted data : AS WKTOSFMDTI RLL SCIWLANOR AUTENENSSNNWT LLM CXOPROIAYBO EEIOOSAST 4b. Print all characters row wise starting from M to K.j<strlen(wrd).i<strlen(wrd). 6. See if input has a multiple of length of word characters. char data[100]. for(i=0.e.h> # include<string. Find position of first character i. print that it is an error and quit. for(j=0. If its not a multiple. Put size of data/size of word characters underneath it.j.e.cipher[c][j]).c. char cipher[8][20].++j) 15/28 . 4.Decryption of a given message by Transposition Method Algorithm for Decryption by Transposition Method 1. Get data to be decoded. 3.++j) printf("%c". MEGABUCK 2. int i. A 5. 7.CCN Lab Manual for(j=0.cnt.h> void main() { char wrd[]="MEGABUCK". int seq[8].j<cnt/strlen(wrd) || j==0.++i) { cnt=0.

seq[i]=cnt.++i) { for(c=0. else { for(i=0.') cipher[j][cnt/strlen(wrd)-1]=' '. } /*get weights of MEGABUCK*/ printf("\nEnter data:").3 indices got by cnt/strlen(wrd). ‘i’ indicates which column weight to feed data under and also number of cnt/strlen(wrd) set of characters have been placed already so now as cnt/strlen(wrd) is 4 for 24 chars.e.gets(data).CCN Lab Manual if(wrd[i]>wrd[j]) ++cnt. cnt=strlen(data).1..i<strlen(wrd).++c) if( seq[c]==i) break.' with ' ' */ { if(cipher[j][cnt/strlen(wrd)-1]=='. column to place data under for 24 letters input there will 4 rows or 0. for first row 0-3 chars are placed next 4-7 (ie cnt/strlen(wrd) which is 4) + j where j goes from 0 to cnt/strlen(wrd) */ for(j=0. for(i=0. } printf("\nDecrypted data : \n").2..++i) /* print out row wise */ printf("%c". /* Find location where data should be placed i.c<strlen(wrd).j<cnt/strlen(wrd).cipher[i%strlen(wrd)][i/strlen(wrd)]).i<cnt. if(cnt%strlen(wrd)!=0) /*if input is not a multiple of 8 for megabuck*/ printf("Error invalid input").j<strlen(wrd). } for(j=0.++j) /* replace trailing '. } } Output: 16/28 .++j) cipher[c][j]=data[i*(cnt/strlen(wrd))+j].

G(x).Compute Polynomial Code Checksum for CRC-CCITT The polynomial code (also known as a cyclic redundancy code or CRC code) is widely used. there has been a transmission error. Append r zero bits to the low-order end of the frame. 2. When the receiver gets the checksummed frame. The idea is to append a checksum to the end of the frame in such a way that the polynomial represented by the checksummed frame is divisible by G (x). The algorithm for computing checksum is as follows: 1. Subtract the remainder (which is always r or fewer bits) from the bit string corresponding to xr M(x) using modulo-2 subtraction. When the polynomial code method is employed.0. the sender and receiver must agree upon a generator polynomial. A k-bit frame is regarded as the coefficient list for a polynomial with k terms. and so on. in advance.0. The high-order (left most) bit is the coefficient of xk-1. To compute the checksum for some frame with m bits. Such a polynomial is said to be of a degree k-1. If there is a remainder. Both the high and low-order bits of the generator must be 1. so it now contains m+r bits and corresponds to the polynomial xr M(x). the next bit is the coefficient of xk-2. The result is the 17/28 . ranging from xk-1 to x0.0 and 1 : x5 + x4 + x0.1. 110001 has 6 bits and thus represents a six-term polynomial with coefficients 1. it tries dividing it by G(x). the frame must be longer than the generator polynomial. For example. Divide the bit string corresponding to G(X) into the bit string c orresponding to xr M(x) using modulo-2 division. Let r be the degree of G(x). Polynomial codes are based upon treating bit strings as representations of polynomials with coefficients of 0 and 1 only. corresponding to the polynomial M(x).CCN Lab Manual Enter data: AS WKTOSFMDTI RLL SCIWLANOR AUTENENSSNNWT LLM CXOPROIAYBO EEIOOSAST Decrypted data : PLEASE TRANSFER ONE MILLION DOLLARS TO MY SWISS BANK ACCOUNT SIX TWO TWO 5. 3.

pos).0. } 18/28 .h> # include <conio. } void calc_CRC(int length) { int ccitt[]={1.0.0.0.newpos.pos=0. while(pos<length-DEGREE) { /* Performing mod-2 division for DEGREE number of bits */ for (i=pos.0.0. int mod2add(int x.1. return i.1}. Call its polynomial T(x).0.0.0. The CRC-CCITT polynomial is x16 + x12 + x5 + 1 /* C Program to compute polynomial code checksum */ # include <stdio.0. } int getnext(int array[].int pos) { int i=pos.0.i<pos+DEGREE+1.h> # define DEGREE 16 /* Degree of the generator polynomial */ int result[30]. newpos=getnext(result.0.++i) result[i]=mod2add(result[i]. /* Generator polnomial */ int i=0. /* Skipping the mod-2 division if lesser than DEGREE bits are available for division */ pos=newpos.0.ccitt[i-pos]).int y) /* Function to perform mod-2 addition */ { return (x==y ? 0 : 1).CCN Lab Manual checksummed frame to be transmitted. /* Checking of the bits are all zeros and skipping */ while(array[i]==0) ++i.1.

for (i=length-DEGREE.i<length. calc_CRC(length).result[i]). clrscr().i<length-DEGREE. } 19/28 . printf("\nEnter the stream for which CRC has to be checked : ").++i) /* Printing the checksum */ printf("%d ".++i) /* Printing the checksum */ printf("%d ". /* Inputting the stream to be checked */ while((ch=getche())!='\r') array[i++]=ch-'0'.++i) array[i+length]=0. /* Inputting data */ printf("Enter the data stream : ").i++) result[i]=array[i]. int length. /* Duplicating the data input */ for (i=0.i<DEGREE. while((ch=getche())!='\r') array[i++]=ch-'0'.i=0.i<length. length+=DEGREE. length=i. for (i=0.i<length.result[i]). /* Appending zeros */ for (i=0.i++) result[i]=array[i]. /* Duplicating the array */ for (i=0.array[i]). calc_CRC(length). /* Calculation of CRC */ printf("\nChecksum : ").i<length. length=i.CCN Lab Manual } void main() { int array[30]. getch().ch. /* Calculation of CRC */ printf("\nThe transmitted frame is : "). i=0.++i) /* Printing the data */ printf("%d ". for (i=length-DEGREE.

Input source. which are connected to working node. To find a route between a pair of routers. Make all nodes TENTATIVE. Initially no paths are known so all nodes are labeled with infinity. 5. Input graph data 2. the working node 4. Routing algorithms can be made to adapt to average traffic/loss/delay/distance /queue length etc. As the algorithm proceeds and paths are found.one where the decision is fixed and one where the route is constantly being recalculated for the best route in other words static and dynamic routing algorithms or Non-Adaptive and Adaptive algorithms. A label maybe either tentative or permanent. Initially all nodes are tentative and once it is discovered that the shortest possible path to a node is got it is made permanent and never changed after that. Dijkstra's method of computing the shortest path or shortest path routing is a static routing algorithm. Check all tentative nodes. Update 20/28 . the labels may change. with each node of the graph representing a router and each arc representing a communication line or a link. Simulate the Shortest Path Algorithm All packets need to be routed form the source to the destination and in most cases multiple hops are required. Routing algorithms are required to decide on which output line an incoming packet should be forwarded onto. the algorithm just finds the shortest path between them on the graph. Make source. destination 3. Make the working node PERMANENT. Each node is labeled with its distance from the source node along with the previous node in the path.CCN Lab Manual Output: Enter the data stream : 10011 The transmitted frame is : 1 0 0 1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 Enter the stream for which CRC has to be checked : 100110010001001010010 Checksum : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6. Algorithm 1. Two types of routing algorithms now come in . It involves building a graph of the subnet. 2. reflecting better paths. In Dijkstra's algorithm the metric used for calculation is distance.

1.0. /*I*/ {0. /*previous node or is connected to*/ int state.2.working_node. /*H*/ {0.0.0. Find TENTATIVE node with smallest weight.0.0.2. dest is destination*/ unsigned int min.1.0.0.3.0.0.0.0.1. /*C*/ {0.0. void main() { int table[NUM_OF_NODES][NUM_OF_NODES] = { /* A B C D E F G H I J*/ /*A*/ {0.1. /*G*/ {0.0}. /*src is source.0.3.0.h> /*Total number of nodes in network*/ # define NUM_OF_NODES 10 /*State of each node*/ # define PERMANENT 1 # define TENTATIVE 0 struct node { unsigned int weight.0}.1.0.4.0}.0.0.3.2.0./* A B C D E F G H I J*/ /*interpret as A is connected to B at a weight of 1 as table[A][B]=table[B][A]=1*/ int src.0.3.0.dest.2}.0.0.0.0.1}.2}.0.2.1. 21/28 .1.3.0.0.2.0.0.0}.0.2.0.h> # include<conio.0. 7.1.0}. /*D*/ {0.1. /*state of the node*/ }.0} }.0.3.4. 6.0.0.0.1.i.0.0.0.0. If working node is destination.0.0.0.0. Trace back from destination to source. /*F*/ {4. Make this the new working node.0.0. /*weight of node therefore -1 is max value*/ int prev.0. /*B*/ {1.0.0}.0.0.0.CCN Lab Manual weight if required. /*J*/ {0. /* Program to calculate one Shortest Path – Tanenbaum approach*/ # include<stdio.0.0. go to step 8 else go to step 4 8.0.4. /*E*/ {0.0.

i<NUM_OF_NODES.state=PERMANENT.state=TENTATIVE.state==TENTATIVE) { /*if connection exists and Node i is tentative*/ if(nodes[working_node]. /*source is working node initially and has prev=-1 and weight=0*/ nodes[src]. } printf("\nEnter Source:").weight=nodes[working_node]. /*update weight and previous node*/ } 22/28 . nodes[src].prev=working_node. src=getche().weight) { /*If lesser weight is achieved with this node as previous node*/ nodes[i].++i) { nodes[i]. for(i=0.weight=0. dest=toupper(getche())-'A'.prev=-1.CCN Lab Manual struct node nodes[NUM_OF_NODES].i<NUM_OF_NODES.++i) { if(table[working_node][i]!=0 && nodes[i]. printf("\nEnter Destination:"). do { /*make working node permanent*/ nodes[working_node].weight+table[working_no de][i] <nodes[i]. nodes[i]. /*convert src character to uppercase then subtract 'A' from it to get src index*/ working_node=src=toupper(src)-'A'. nodes[i].weight=-1.weight+ table[working_node][i]. /*initialize all nodes as tentative and having weight of -1 or maximum*/ for(i=0.

working_node+65).weight).i<NUM_OF_NODES.weight.prev!=-1).nodes[dest].dest+65).++i) { if(nodes[i]. for(i=0. working_node=i.weight<min) { min=nodes[i]. /*print shortest path by traversing back through node::prev*/ printf("\nShortest Path got--->\n%c". printf("\nAt a total weight of:%d".state==TENTATIVE && nodes[i].prev.CCN Lab Manual } } /*Find minimum weighted Tentative node*/ min=-1. printf("<-%c". do { working_node=nodes[working_node]. } Output: Enter Source:A Enter Destination:D Shortest Path got---> D<-E<-J<-I<-H<-B<-A At a total weight of: 7 23/28 . } } }while(working_node!=dest). }while(nodes[working_node].

This method makes excellent use of bandwidth.h> struct node { int set. 24/28 . Input the edge weights 3.g. with distance vector routing). Before joining two nodes. the join is not performed. /* Program for finding the Minimum Spanning Tree of a network */ #include<stdio. Input number of vertices 2.CCN Lab Manual 7.h> #include<conio. the variable ‘set’ is used to eliminate closed loops. different trees have different lengths. Find Minimum Spanning Tree of a Subset A spanning tree is a graph is just a sub-graph that contains all the vertices and is a tree. A spanning tree includes all the routers but contains no loops. with link state routing) but sometimes it is not (e. Obviously. /*Attribute to indicate which connection the node belongs to*/ }node[10]. the weight of tree is the sum of its edges. If the nodes are of different ‘sets’ then they are joined and then made of the same set. each node’s ‘set’ is checked and if found to be the same. If each router knows which of its lines belong to the spanning tree. Sort the edge weights in ascending order 4. Repeat till edges are marked making sure that there are no closed loops (number of vertices –1) 6. generating the absolute minimum number of packets necessary to do the job. it can copy an incoming broadcast packet onto all the spanning tree lines except the one it arrived on.g. For instance. 1. Display selected edges. Suppose the edges of the graphs have weights or lengths. A graph may have many spanning trees. Finding the minimum spanning tree The easiest to understand and probably the best one for solving problems by hand is Kruskal’s algorithm. NOTE: In the program given. The only problem is that each router must have knowledge of some spanning tree for it to be applicable. a complete graph of 4 nodes can have 16 spanning trees. Pick the lowest edge and join the corresponding vertices 5. Sometimes this information is available (e.

&e[edge_count].CCN Lab Manual struct edge { int first_node. index+65.selected= -1. /* If no connection between nodes */ if(e[edge_count].distance==0) --edge_count. /* To denote whether edge is seleted*/ }e[10]. void getdata( int index. i<edge_count-1. e[edge_count]. i<total. /* distance between the nodes*/ int selected. struct edge temp.distance). scanf("%d". j<edge_count-i-1. e[edge_count]. for(i=index. for(i=0. ++edge_count. int distance. int edge_count = 0. i+65).second_node=i. second_node. ++i) { if(i!= index) { printf("Enter distance between vertex %c and %c:". ++i) for(j=0. ++j) 25/28 .j. e[edge_count]. int total) /* Function to input the distance*/ { int i. } } } void sort_edges() /* Sort using Bubble sort */ { int i.first_node=index.

/* Node on left of the edge */ nodeR = e[i]. } sort_edges().distance). do { e[i].second_node+65.selected = 1. e[j+1]=temp. scanf("%d".selected = -1. /* Deselect the edge */ 26/28 .nodeR.cost=0. for(i=0.CCN Lab Manual { { if(e[j].set = i. } } } } void main() { int total_vertices. printf("\nEnter the no. for(i=0. /* node on the right of the edge */ /* If the set value is the same do not select that edge */ if(node[nodeL]. i<edge_count. /* Edge is selected */ nodeL = e[i]. ++i) { node[i]. of vertices:").distance > e[j+1]. getdata(i.edges_selected=0. e[i]. e[j]=e[j+1].first_node+65.distance) { temp=e[j].j. ++i) printf("\nEdge: %d First:%c Second:%c Distance:%d". &total_vertices).m.first_node.k.nodeL.set == node[nodeR].second_node.n. e[i]. i. e[i].set) e[i]. total_vertices). /*Finding minimum spanning tree*/ i=0. clrscr(). printf("\n Sorted order of the edges\n"). i<total_vertices.i.

} } ++i.first_node+65. cost). n<total_vertices.e[i]. for(n=0. ++n) { /* Making all nodes of the same set */ if(node[n]. printf("\n %c<--->%c Distance:%d". i<edge_count.CCN Lab Manual else { edges_selected++.second_node+65.distance.++i) if(e[i].set.e[i]. } while(edges_selected < (total_vertices-1)). } printf("\n\n Cost = %d". /* Check till total nodes-1 edges are formed */ printf("\n\n Minimum spanning tree:\n").set. m = node[nodeL].selected == 1) { cost+= e[i]. for(i=0. } OUTPUT: Output: Enter the number of vertices: 4 Enter distance between vertex A and B: 7 Enter distance between vertex A and C: 0 Enter distance between vertex A and D: 4 Enter distance between vertex B and C: 3 Enter distance between vertex B and D: 2 27/28 .set = m. k = node[nodeR].set == k) node[n]. e[i]. getch().distance).

CCN Lab Manual Enter distance between vertex C and D: 1 Sorted order of edges: Edge: 0 First Node: C Seconde Node: D Distance: 1 Edge: 1 First Node: B Seconde Node: D Distance: 2 Edge: 2 First Node: B Seconde Node: C Distance: 3 Edge: 3 First Node: A Seconde Node: D Distance: 4 Edge: 4 First Node: A Seconde Node: B Distance: 7 Minimal Spanning Tree: C<-->D Distance: 1 B<-->D Distance: 2 A<-->D Distance: 4 Cost: 7 28/28 .

- CCN Lab Manual TE VTU
- Cn Lab Manual
- Character Stuffing
- Cn Lab Manual
- Computer Network Student File
- CN Lab Manual MIT
- JNTU B.tech Computer Networks Lab Manual All Programs (1)
- Computer Network Lab Viva Questions
- network security manual
- Computer Networks Lab Manual Latest
- Cn Lab Manual
- Computer Networks Lab Manual
- Networking Practical File
- wireless communication
- Microwave Lab Manual
- Advanced Computer Networks Practical File
- Computer Organization Hamacher Instructor Manual Solution - Chapter 8
- Final VLSI LAB Digital Analog Record 2
- Computer Organization Hamacher Instructor Manual solution - chapter 5.pdf
- DC Lab Manual
- 5th Sem Dbms Lab Programs
- 06CSL77 - Networks Manual
- Ccp Lab Manual2010
- Embedded Systems Lab Manual
- CCN notes for unit 1. VTU students. Prof.suresha V
- Monochrome and Colour- R R Gulathi
- Embedded System Lab Manual Final Complete Final
- ccn labview
- CN-RECORD.doc
- CN-RECORD
- CCN Lab Manual Programs

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd