Skip to main content

SIMULATION OF ROUTING PROTOCOLS USING C


#include<stdio.h>
#include<ctype.h>
int graph[12][12];
int e[12][12];
int ad[12];
int no,id,adc,small,chosen,i,j,ch1,ch2;
char nodes[12]={"abcdefghijkl"};
int main()
{
adc=0;
printf("Enter The Number Of Nodes: ");
scanf("%d",&no);
printf("\nEnter The Values For Adjacency Matrix\n");
for(i=0;i <no;i++)
{
for(j=0;j <no;j++)
{
printf("Enter The Values For %d,%d Position: ",(i+1),(j+1));
scanf("%d",&graph[i][j]);
}
}
printf("\nEnter The Initial Estimates\t");
for(i=0;i <no;i++)
{
printf("\nEstimate For Node %c:\n",nodes[i]);
for(j=0;j <no;j++)
{
printf("To Node %c : ",nodes[j]);
scanf("%d",&e[i][j]);
}
}
do
{
printf("\nMENU:\n1.ROUTING INFO FOR NODE");
printf("\n2.ESTIMATED TABLE\n");
printf("Enter Your Choice: ");
scanf("%d",&ch1);
switch(ch1)
{
case 1:
printf("\nWhich Node Should Routing Table Be Built? (1-a)(2-b)...");
scanf("%d",&id);
id--;
adc=0;
printf("\nNeighbours For Particular Node ");
for(i=0;i <no;i++)
{
if(graph[id][i]==1)
{
ad[adc]=i;
adc++;
printf("%c",nodes[i]);
}
}
for(i=0;i <no;i++)
{
if(id!=i)
{
small=100;
chosen=1;
for(j=0;j <no;j++)
{
int total=e[ad[j]][i]+e[id][ad[j]];
if(total <100)
{
small=total;
chosen=j;
}
}
e[id][i]=small;
printf("\nShortest Estimate To %c is %d",nodes[i],small);
printf("\nNext Hop Is %c",nodes[ad[chosen]]);
}
else
e[id][i]=0;
}
break;
case 2:
printf("\n");
for(i=0;i <no;i++)
{
for(j=0;j <no;j++)
printf("%d ",e[i][j]);
printf("\n");
}
break;
}
printf("\nDo You Want To Continue?(1-YES) (2-NO): ");
scanf("%d",&ch2);
}
while(ch2==1);
return 0;
}

OUTPUT
$ cc simulation.c
$ ./a.out
Enter The Number Of Nodes: 2
Enter The Values For Adjacency Matrix
Enter The Values For 1,1 Position: 1
Enter The Values For 1,2 Position: 2
Enter The Values For 2,1 Position: 3
Enter The Values For 2,2 Position: 4
Enter The Initial Estimates
Estim ate For Node a:
To Node a : 1
To Node b : 2
Estimate For Node b:
To Node a : 1
To No de b : 2
MENU:
1.ROUTING INFO FOR NODE
2.ESTIMATED TABLE
Enter Your Choice: 1
Which Node Should Routing Table Be Built? (1-a)(2-b)...1
Neighbours For Particular Nodea
Shortest Estimate To b is 2
Next Hop Is a
Do You Want To Continue?(1-YES) (2-NO): 1
MENU:
1.ROUTING INFO FOR NODE
2.ESTIMATED TABLE
Enter Your Choice: 2
0 2
1 2
Do You Want To Continue?(1-YES) (2-NO): 2
$



Comments

Popular posts from this blog

CALCULATOR USING CONTROL ARRAY

Public curval As Double Public preval As Double Public choice As String Public result As Double Private Sub cmd_Click(Index As Integer) Text1.Text = Text1.Text &cmd(Index).Caption curval = Val(Text1.Text) End Sub Private Sub cmdac_Click() curval = preval = 0 Text1.Text = "" End Sub Private Sub cmddiv_Click() Text1.Text = "" preval = curval curval = 0 choice = "/" End Sub Private Sub cmdequal_Click() Select Case choice Case "+" result = preval + curval Text1.Text = Str(result) Case "-" result = preval - curval Text1.Text = Str(result) Case "*" result = preval * curval Text1.Text = Str(result) Case "/" result = preval / curval Text1.Text = Str(result) End Select curval = result End Sub Private Sub CMDEXIT_Click() End End Sub Private Sub cmdminus_Click() Text1.Text = "" preval = curval curval = 0 choice = "-" End Sub Private Sub cmdmul_Click() Text1.Text = ...

TCP SOCKET DATE AND TIME USING C

SERVER #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<time.h> #include<string.h> #include<stdlib.h> #define max 30 #define PORT 2100 int main() { int sersoc,clisoc,conn,len,wri; char str[max]; pid_t pid; time_t ticks; socklen_t clilen; struct sockaddr_in servaddr,cliaddr; servaddr.sin_family=AF_INET; servaddr.sin_port=htons(PORT); servaddr.sin_addr.s_addr=htonl(INADDR_ANY); if((sersoc=socket(AF_INET,SOCK_STREAM,0))<0) { perror("Socket Error"); exit(0); } if(bind(sersoc,(struct sockaddr *)&servaddr,sizeof(servaddr))<0) { perror("Bind Error"); exit(0); } listen(sersoc,10); for(;;) { len=sizeof(cliaddr); conn=(accept(sersoc,(struct sockaddr *)&clisoc,&len)); if((pid=fork())==0) { close(sersoc); ticks=time(NULL); strcpy(str,ctime(&ticks)); if(wri==(write(conn,str,sizeof(str),0))<0) { printf("Write Error");...

SIMULATION OF SLIDING WINDOW PROTOCOLS USING C

SENDER #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<netdb.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<unistd.h> #include<errno.h> int main() { int sock,bytes_received,connected,true=1,i=1,s,f=0,sin_size; char send_data[1024],data[1024],c,fr[30]=" "; struct sockaddr_in server_addr,client_addr; if((sock=socket(AF_INET,SOCK_STREAM,0))==-1) { perror("Socket not created"); exit(1); } if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(int))==-1) { perror("Setsockopt"); exit(1); } server_addr.sin_family=AF_INET; server_addr.sin_port=htons(17000); server_addr.sin_addr.s_addr=INADDR_ANY; if(bind(sock,(struct sockaddr *)&server_addr,sizeof(struct sockaddr))==-1) { perror("Unable to bind"); exit(1); } if(listen(sock,5)==-1) { perror("Listen"); exit(1); } fflush(stdout); sin_size=sizeof(st...