• No results found

computer network practical file

N/A
N/A
Protected

Academic year: 2021

Share "computer network practical file"

Copied!
17
0
0

Loading.... (view fulltext now)

Full text

(1)

AIM-WAP FOR DESIGNING OSI MODEL

Description-In data transmission and telecommunication, bit stuffing (also known—uncommonly— as positive justification) is the insertion of non information bits into data. Stuffed bits should not be confused with overhead bits.

Bit stuffing is used for various purposes, such as for bringing bit streams that do not necessarily have the same or rationally related bit rates up to a common rate, or to fill buffers or frames. The location of the stuffing bits is communicated to the receiving end of the data link, where these extra bits are removed to return the bit streams to their original bit rates or form. Bit stuffing may be used to synchronize several channels before multiplexing or to rate-match two single channels to each other. Applications include Plesiochronous Digital Hierarchy and Synchronous Digital Hierarchy.

Another use of bit stuffing is for run length limited coding: to limit the number of consecutive bits of the same value in the data to be transmitted. A bit of the opposite value is inserted after the maximum allowed number of consecutive bits. Since this is a general rule the receiver doesn't need extra

information about the location of the stuffing bits in order to do the de stuffing. Program- #include< stdlib.h> #include< graphics.h> #include< conio.h> #include< stdio.h> void main() {

int driver, mode; int i,j;

driver = DETECT;

initgraph(&driver,&mode,"");

outtextxy(250,450,"ISO OSI Model"); delay(2000); outtextxy(90,30,"Sender"); delay(500); setcolor(6); for(i=50;i< =350;i+=50) { rectangle(200,i,50,i+30); delay(500); } setcolor(10); outtextxy(70,60,"Application"); delay(500); outtextxy(70,110,"Presentation"); delay(500); outtextxy(70,160,"Session"); delay(500); outtextxy(70,210,"Transport");

(2)

delay(500); outtextxy(70,260,"Network"); delay(500); outtextxy(70,310,"Data Link"); delay(500); outtextxy(70,360,"Physical"); delay(500); setcolor(15); outtextxy(390,30,"Receiver"); delay(500); setcolor(6); for(i=50;i< =350;i+=50) { rectangle(350,i,500,i+30); delay(500); } setcolor(10); outtextxy(370,60,"Application"); delay(500); outtextxy(370,110,"Presentation"); delay(500); outtextxy(370,160,"Session"); delay(500); outtextxy(370,210,"Transport"); delay(500); outtextxy(370,260,"Network"); delay(500); outtextxy(370,310,"Data Link"); delay(500); outtextxy(370,360,"Physical"); delay(500); // sender Lines line(120,80,120,100); delay(500); line(120,130,120,150); delay(500); line(120,180,120,200); delay(500); line(120,230,120,250); delay(500); line(120,280,120,300); delay(500); line(120,330,120,350); delay(500); line(120,380,120,400); delay(500); // Physical Connection line(120,400,420,400);

(3)

// Receiver Lines line(420,380,420,400); delay(500); line(420,330,420,350); delay(500); line(420,280,420,300); delay(500); line(420,230,420,250); delay(500); line(420,180,420,200); delay(500); line(420,130,420,150); delay(500); line(420,80,420,100); //virtual connection setcolor(15); delay(500); outtextxy(210,35,"Virtual Connection"); delay(1000); for(j=65;j< =365;j+=50) { for(i=0;i< 15;i++) { setcolor(i); line(200,j,230,j); delay(10); line(235,j,265,j); delay(10); line(270,j,300,j); delay(10); line(305,j,335,j); delay(10); line(340,j,350,j); delay(10); } } delay(500); }

AIM-WAP FOR FINDING EVEN AND ODD PARITY

(4)

1-bits. The number

has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits.

Main idea of the below solution is – Loop while n is not 0 and in loop unset one of the set bits and invert parity. Algorithm: getParity(n) 1. Initialize parity = 0 2. Loop while n != 0 a. Invert parity parity = !parity b. Unset rightmost set bit n = n & (n-1) 3. return parity Example: Initialize: n = 13 (1101) parity = 0 n = 13 & 12 = 12 (1100) parity = 1 n = 12 & 11 = 8 (1000) parity = 0 n = 8 & 7 = 0 (0000) parity = 1 Program- # include <stdio.h> # define bool int

/* Function to get parity of number n. It returns 1 if n has odd parity, and returns 0 if n has even parity */

bool getParity(unsigned int n) { bool parity = 0; while (n) { parity = !parity; n = n & (n - 1); } return parity; }

/* Driver program to test getParity() */ int main()

{

unsigned int n = 7;

printf("Parity of no %d = %s", n, (getParity(n)? "odd": "even"));

(5)

return 0; }

AIM-WAP TO IMPLIMENT DATA LINK LAYER FRAMING METHOD AS BIT STUFFING Description-In data transmission and telecommunication, bit stuffing (also known—uncommonly— as positive justification) is the insertion of non information bits into data. Stuffed bits should not be confused with overhead bits.

(6)

Bit stuffing is used for various purposes, such as for bringing bit streams that do not necessarily have the same or rationally related bit rates up to a common rate, or to fill buffers or frames. The location of the stuffing bits is communicated to the receiving end of the data link, where these extra bits are removed to return the bit streams to their original bit rates or form. Bit stuffing may be used to synchronize several channels before multiplexing or to rate-match two single channels to each other. Applications include Plesiochronous Digital Hierarchy and Synchronous Digital Hierarchy.

Another use of bit stuffing is for run length limited coding: to limit the number of consecutive bits of the same value in the data to be transmitted. A bit of the opposite value is inserted after the maximum allowed number of consecutive bits. Since this is a general rule the receiver doesn't need extra

information about the location of the stuffing bits in order to do the de stuffing.

This is done to create additional signal transitions to ensure reliable reception or to escape special reserved code words such as frame sync sequences when the data happens to contain them. Applications include Controller Area Network, HDLC, and Universal Serial Bus.

Program- #include<stdio.h> #include<conio.h> main() { char a[20],fs[50]="",t[6],r[5]; int i,j,p=0,q=0; clrscr();

printf("enter bit string : "); scanf("%s",a); strcat(fs,"01111110"); if(strlen(a)<5) { strcat(fs,a); } else { for(i=0;i { for(j=i;j { t[p++]=a[j]; } t[p]='\0'; if(strcmp(t,"11111")==0) { strcat(fs,"111110"); i=j-1; } else {

(7)

r[0]=a[i]; r[1]='\0'; strcat(fs,r); } p=0; } for(q=i;q { t[p++]=a[q]; } t[p]='\0'; strcat(fs,t); } strcat(fs,"01111110"); printf("After stuffing : %s",fs); getch(); }

AIM-WAP FOR CHARACTER COUNT

Description-Character-count integrity is a telecommunications term for the ability of a certain link to preserve the number of characters in a message (per unit time, in the case of a user-to-user connection). Character-count integrity is not the same as character integrity, which requires that the characters delivered be, in fact, exactly the same as they were originated.

(8)

Program- #include<stdio.h> #include<conio.h> main() { char a[30],fs[50]="",t[3],sd,ed,x[3],s[3],d[3],y[3]; int i,j,p=0,q=0; clrscr();

printf("Enter characters to be stuffed : "); scanf("%s",a);

printf("\nEnter a character that represents starting delimiter : "); scanf(" %c",&sd);

printf("\nEnter a character that represents ending delimiter : "); scanf(" %c",&ed); x[0]=s[0]=s[1]=sd; x[1]=s[2]='\0'; y[0]=d[0]=d[1]=ed; d[2]=y[1]='\0'; strcat(fs,x); for(i=0;i { t[0]=a[i]; t[1]='\0'; if(t[0]==sd) strcat(fs,s); else if(t[0]==ed) strcat(fs,d); else strcat(fs,t); } strcat(fs,y); printf("\nAfter stuffing : %s",fs); getch(); }

AIM-WAP TO FOR PURE AND SLOTTED ALOHA

Description-1) Pure Aloha is a Continuous time system whereas Slotted Aloha is discrete time system. 2) Pure ALOHA doesn't check whether the channel is busy before transmission.

Slotted ALOHA send the data at the beginning of timeslot.

3) Pure aloha not divided in to time .Slotted aloha divided in to time Program-

(9)

#include <stdio.h> #include <math.h> #include <time.h> #include <dos.h> #define FRAME_TIME 250 main() { float S1, S2, G, J, val[100] ; int I, n, K, delay ; void wait() ; clrscr() ;

printf("Please Give the Total Load : "); scanf("%d", &n);

printf("Please Enter the value of load \n"); for (I=0; I<n; I++)

{

scanf("%f", &val[I]); }

clrscr();

printf("\nOUTPUT 1: (THROUGHPUT Vs LOADCURVE)\n\n"); printf("s=g*exp(-G) FOR SLOTTED ALOHA * \n");

printf("s=g*exp(-2G) FOR PURE ALPHA #\n");

printf("\n--- (THROUGHPUT PER FRAME TIME)----\n"); for(K=0; K<n; K++) { G=val[K]; S1 = G * exp (-G); S2 = G * exp(-2 * G); printf("%1.3f", G ); for (I=0; I <=S1*20; I++) {

printf(" "); }

printf("*");

for(I=S2*20; I<=S2*75; I++ ) {

printf(" "); }

printf("#\n"); }

printf("G (ATTEMPTS PER PACKET TIME) \n\n"); wait() ;

getch() ; clrscr() ;

printf("\nOUTPUT 2 (DELAY Vs THROUGHPUT) \n\n"); printf("\n---(THOUGHPUT PER FRAME TIME)----\n"); for(K=0; K<n; K++)

(10)

{

G=val[K];

S1 = G * exp (-G); printf("3");

for (I=0; I <=S1*2.7; I++) { printf(" "); } printf("*\n"); } printf("\n"); printf("---- DELAY ---"); wait(); getch(); clrscr(); } void wait() { sound(440); delay(300); nosound(); }

AIM-WAP TO FIND SHORTEST PATH USING DIJKSTRA's ALGORITHM

Description-Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1956 and published in 1959, is a graph search algorithmthat solves the single-source shortest path problem for a graph with non-negative edge path costs, producing a shortest path tree. This algorithm is often used in routing as a subroutine in other graph algorithms, or in GPS Technology.

For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex. It can also be used for finding costs of shortest paths from a single vertex to a single destination vertex by stopping the algorithm once the

(11)

shortest path to the destination vertex has been determined. For example, if the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road, Dijkstra's algorithm can be used to find the shortest route between one city and all other cities. As a result, the shortest path first is widely used in network routing protocols, most notably IS-IS and OSPF (Open Shortest Path First).

Dijkstra's original algorithm does not use a min-priority queue and runs in O(|V|2).The idea of this algorithm is also given in (Leyzorek et al. 1957). The implementation based on a min-priority queue implemented by a Fibonacci heap and running in O(|E|+V|log V|).

Program-

#include <stdio.h> #include <conio.h> #define infinity 999

void dij(int n,int v,int cost[10][10],int dist[]) { int i,u,count,w,flag[10],min; for(i=1;i<=n;i++) flag[i]=0,dist[i]=cost[v][i]; count=2; while(count<=n) { min=99; for(w=1;w<=n;w++)

if(dist[w]<min && !flag[w]) min=dist[w],u=w;

flag[u]=1; count++;

for(w=1;w<=n;w++)

if((dist[u]+cost[u][w]<dist[w]) && !flag[w]) dist[w]=dist[u]+cost[u][w]; } } void main() { int n,v,i,j,cost[10][10],dist[10]; clrscr();

printf("\n Enter the number of nodes:"); scanf("%d",&n);

printf("\n Enter the cost matrix:\n"); for(i=1;i<=n;i++)

for(j=1;j<=n;j++) {

scanf("%d",&cost[i][j]); if(cost[i][j]==0)

(12)

cost[i][j]=infinity; }

printf("\n Enter the source matrix:"); scanf("%d",&v);

dij(n,v,cost,dist);

printf("\n Shortest path:\n"); for(i=1;i<=n;i++)

if(i!=v)

printf("%d->%d,cost=%d\n",v,i,dist[i]); getch();

}

AIM-WAP FOR FINDING SHORTEST PATH BY DISTANCE VECTOR ROUTING

Description- Distance Vector means that Routers are advertised as vector of distance and Direction. Direction is simply next hop address and exit interface and Distance means hop count.

Routers using distance vector protocol do not have knowledge of the entire path to a destination. Instead DV uses two methods:

Direction in which router or exit interface a packet should be forwarded. Distance from its destination.

In distance vector routing, the least cost route between any two nodes is the route with minimum distance. In this protocol, as the name implies, each node maintains a vector (table) of minimum distance to every node. As the name suggests the DV protocol is based on calculating the direction and distance to any link in a network. The cost of reaching a destination is calculated using various route

(13)

metrics. RIP uses the hop count of the destination whereas IGRP takes into account other information such as node delay and available bandwidth.

Program- #include<stdio.h> #include<conio.h> struct node { unsigned dist[20]; unsigned from[20]; }rt[10]; int main() { int dmat[20][20]; int n,i,j,k,count=0; clrscr();

printf(“\nEnter the number of nodes : “); scanf(“%d”,&n);

printf(“\nEnter the cost matrix :\n”); for(i=0;i for(j=0;j<n;j++) { scanf(“%d”,&dmat[i][j]); dmat[i][i]=0; rt[i].dist[j]=dmat[i][j]; rt[i].from[j]=j; } do { count=0; for(i=0;i for(j=0;j<n;j++) for(k=0;k<n;k++) if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j]) { rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]; rt[i].from[j]=k; count++; } }while(count!=0); for(i=0;i<n;i++) {

printf(“\n\nState value for router %d is \n”,i+1); for(j=0;j<n;j++)

{

printf(“\t\nnode %d via %d Distance%d”,j+1,rt[i].from[j]+1,rt[i].dist[j]); }

(14)

}

printf(“\n\n”); }

AIM-WAP TO FIND CLASSES OF IP ADDRESS

Description-An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication.An IP address serves two principal functions: host or network

interface identification and location addressing. Its role has been characterized as follows:

"A name indicates what we seek. An address indicates where it is. A route indicates how to get there." if first three bits are in 0-127 then Class A

if first three bits are in 128-191 then Class B if first three bits are in 192-223 then Class C if first three bits are in 224-239 then Class D if first three bits are in 240-255 then Class E

(15)

Program- #include<stdio.h> #include<conio.h> void main() { int a,b,c,d; clrscr();

printf(“Enter The IP Address of Format xxx.yyy.p.q”); scanf(“%d %d %d %d”,&a,&b,&c,&d);

printf(“The IP Address entered is %d.%d.%d.%d”,a,b,c,d); printf(“Entered IP is of CLASS”);

if(a<=0 && a>=127) {

printf(“IP address is of class A”); }

if(a<=128 && a>=191) {

printf(“IP address is of class B”); }

if(a<=192 && a>=223) {

printf(“IP address is of class C”); }

if(a<=224 && a>=239) {

printf(“IP address is of class D”); }

if(a<=240 && a>=255) {

printf(“IP address is of class E”); }

}

AIM-WAP FOR SUBSTITUTION CIPHER

Description-In cryptography, a substitution cipher is a method of encoding by which units of plaintext are replaced with ciphertext, according to a regular system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution.

Substitution ciphers can be compared with transposition ciphers. In a transposition cipher, the units of the plaintext are rearranged in a different and usually quite complex order, but the units themselves are left unchanged. By contrast, in a substitution cipher, the units of the plaintext are retained in the same sequence in the ciphertext, but the units themselves are altered.

There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is

termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different positions in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice versa.

(16)

Program- ENCRYPTION #include<stdio.h> #include<string.h> #include<stdlib.h> #include<conio.h> int main(void) { int i,j; char c[]="abcdefghijklmnopqrstuvwxyz ",t; char d[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; FILE *fp; fp=fopen("output.txt","wb+"); if(fp==NULL) {

puts("Cannot open file"); exit(0); } while((t=getchar())!=EOF) { i=0; while(c[i]!=t) i++; putc(d[i],fp); } fclose(fp); } DECRYPTION #include<stdio.h> #include<string.h> #include<stdlib.h> #include<conio.h> int main(void) {

(17)

int i,j; char c[]="abcdefghijklmnopqrstuvwxyz ",t; char d[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; FILE *fp; fp=fopen("output.txt","rb+"); if(fp==NULL) {

printf("Cannot open file"); exit(0); } while((t=getc(fp))!=EOF) { i=0; while(d[i]!=t) i++; fseek(fp,-1L,1); putc(c[i],fp); } fclose(fp); }

References

Related documents

1 = Noise on a valid start bit, any of the data bits, or on the stop bit FE — Framing Error Flag. Set when a zero is detected where a stop bit

In this light, the focus on regimes of border functioning empowers researchers to trace how the uneven development between the two sides of the border – and in a broader context

Description: Broadcast transmission used to discover the 16-bit (network) address of a remote device with a matching 64-bit address.. Field Name Size (bytes)

Luddington of 1912‟s Indian Termination policy, viewed Indian education as a means to “kill the Indian in the child.” By contrast the US desired to “kill the Indian,

Using CA-125 levels in guiding the treatment of patients with asymptomatic recurrent ovarian cancer, who have shown CCR to primary therapy, can facilitate optimal secondary CRS

(Not all instances of laetus in the Aeneid outside Book 5 are discussed in Chapter Two; others are discussed in Chapters Six and Seven.) In Chapter Three I discuss the uses of

With respect to entry, the general rule is the following: alien workers from outside the EU must be hired in their countries of origin when they are hired for the first time,

In this study, we attempted to examine the effects of childhood adversity and resilience on health behaviors in Taiwanese youth.. We hypothesize that childhood adversity is