Anna University Results November - December 2011 available with your GPA only for Credit System

Exam Results 2012

Exam Results 2012 Inspirational Quotes
Showing posts with label Network Lab Programs - CS2307. Show all posts
Showing posts with label Network Lab Programs - CS2307. Show all posts

Saturday, September 18, 2010

OPNET - TCP versus UDP Response Time

Download from here .....

OPNET - TCP versus UDP Response Time

OPNET - TCP Throughput

Download from here .....

OPNET - TCP Throughput

OPNET - Routing Protocols

Download from here .....

OPNET - Routing Protocols

OPNET - Shared Ethernet Networks

Download from here .....

OPNET - Shared Ethernet Networks

Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm)



/* Implementation of Shortest Path Computation in OSPF (Dijikstra’s Algorithm) */

#include<stdio.h>
main()
{
int i,j,k,n,a[10][10],b[10][10];
printf("\n Enter the no.of nodes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n Enter the distance between the host %d to %d : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("\n The given Matrix is : \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(" %d\t",a[i][j]);
}
printf("\n");
}

for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[i][j];
if(i==j)
b[i][j]=0;
}
}


printf("\n The output Matrix is : \n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(" %d \t",b[i][j]);
}
printf("\n");
}
}
OUTPUT :

 Enter the no.of nodes : 4

 Enter the distance between the host 1 to 1 : 0

 Enter the distance between the host 1 to 2 : 2

 Enter the distance between the host 1 to 3 : 5

 Enter the distance between the host 1 to 4 : 3

 Enter the distance between the host 2 to 1 : 2

 Enter the distance between the host 2 to 2 : 0

 Enter the distance between the host 2 to 3 : 6

 Enter the distance between the host 2 to 4 : 1

 Enter the distance between the host 3 to 1 : 3

 Enter the distance between the host 3 to 2 : 1

 Enter the distance between the host 3 to 3 : 0

 Enter the distance between the host 3 to 4 : 6

 Enter the distance between the host 4 to 1 : 3

 Enter the distance between the host 4 to 2 : 1

 Enter the distance between the host 4 to 3 : 5

 Enter the distance between the host 4 to 4 : 0

 The given Matrix is :

 0       2       5       3
 2       0       6       1
 3       1       0       6
 3       1       5       0

 The output Matrix is :

 0       2       5       3
 2       0       6       1
 3       1       0       2
 3       1       5       0

Simulation of Sliding Window Protocol



/* Simulation of Sliding Window Protocol */

// SlideServer.c : A Simple Slide Server Program Using Sliding Window Protocol

#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include<arpa/inet.h>
#define SIZE 4
int main()
{
        int sfd,lfd,len,i,j,status;
        char str[20],frame[20],temp[20],ack[20];
        struct sockaddr_in saddr,caddr;
        sfd=socket(AF_INET,SOCK_STREAM,0);
        if(sfd<0)
                perror("Error");
                bzero(&saddr,sizeof(saddr));
                saddr.sin_family=AF_INET;
                saddr.sin_addr.s_addr=htonl(INADDR_ANY);
                saddr.sin_port=htons(5465);
                if(bind(sfd,(struct sockaddr*)&saddr,sizeof(saddr))<0)
                        perror("Bind Error");
                listen(sfd,5);
                len=sizeof(&caddr);
                lfd=accept(sfd,(struct sockaddr*)&caddr,&len);
                printf(" Enter the text : \n");
                scanf("%s",str);
                i=0;
                while(i<strlen(str))
                {
                        memset(frame,0,20);
                        strncpy(frame,str+i,SIZE);
                        printf(" Transmitting Frames. ");
                        len=strlen(frame);
                        for(j=0;j<len;j++)
                        {
                                printf("%d",i+j);
                                sprintf(temp,"%d",i+j);
                                strcat(frame,temp);
                        }
                        printf("\n");
                        write(lfd,frame,sizeof(frame));
                        read(lfd,ack,20);
                        sscanf(ack,"%d",&status);

                        if(status==-1)
                                printf(" Transmission is successful. \n");
                        else
                        {
                                printf(" Received error in %d \n\n",status);
                                printf("\n\n Retransmitting Frame. ");
                                for(j=0;;)
                                {
                                        frame[j]=str[j+status];
                                        printf("%d",j+status);
                                        j++;
                                    if((j+status)%4==0)
                                                break;
                                }
                                printf("\n");
                                frame[j]='\0';
                                len=strlen(frame);
                                for(j=0;j<len;j++)
                                {
                                        sprintf(temp,"%d",j+status);
                                        strcat(frame,temp);
                                }
                                write(lfd,frame,sizeof(frame));
                        }
                        i+=SIZE;
                }
                write(lfd,"exit",sizeof("exit"));
                printf("Exiting\n");
                sleep(2);
                close(lfd);
                close(sfd);
}




// SlideClient.c : A Simple Slide Client Program Using Sliding Window Protocol

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<netinet/in.h>
int main()
{
        int sfd,lfd,len,choice;
        char str[20],str1[20],err[20];
        struct sockaddr_in saddr,caddr;
        sfd=socket(AF_INET,SOCK_STREAM,0);
        if(sfd<0)
                perror("FdError");
        bzero(&saddr,sizeof(saddr));
        saddr.sin_family=AF_INET;
        saddr.sin_addr.s_addr=INADDR_ANY;
        saddr.sin_port=htons(5465);
        connect(sfd,(struct sockaddr*)&saddr,sizeof(saddr));
        for(;;)
        {
                read(sfd,str,20);
                if(!strcmp(str,"exit"))
                {
                        printf("Exiting\n");
                        break;
                }
                printf("\n\nReceived%s\n\n1.Do u want to report an error(1-Yes 0-No)",str);
                scanf("%d",&choice);
                if(!choice)
                        write(sfd,"-1",sizeof("-1"));
                else
                {
                        printf("Enter the sequence no of the frame where error has occured\n");
                        scanf("%s",err);
                        write(sfd,err,sizeof(err));
                        read(sfd,str,20);
                        printf("\n\nReceived the re-transmitted frames%s\n\n",str);
                }
        }
}

OUT PUT :

SlideServer.c :

cc SlideServer.c
./a.out

Enter the text
jerusalem
Transmitting Frames=0123
Transmission is successful
Transmitting Frames=4567
Received error in 5

Retransmitting Frame=678
Transmitting Frames=8
Received error in 2

Retransmitting Frame=34
Exiting

ClientServer.c :

cc ClientServer.c
./a.out

Received=jeru0123

1.Do u want to report an error(1-Yes 0-No)0


Received=sale4567

1.Do u want to report an error(1-Yes 0-No)1
Enter the sequence no of the frame where error has occured
5

Received the re-transmitted frames=ale567

Received=m8

1.Do u want to report an error(1-Yes 0-No)1
Enter the sequence no of the frame where error has occured
2
Received the re-transmitted frames=ru23
Exiting


Implementation of Distance Vector Routing



/* Implementation of Distance Vector Routing */

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int i,j,k,n,a[10][10],b[10][10],src,s,d;
char ch;
clrscr();
printf("\n Enter the number of nodes = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
a[i][j]=0;
else
{
printf("\n Enter the distance between host : %d and %d ==> ",i,j);
scanf("%d",&a[i][j]);
}
}
}
printf("\n ");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n ");
}
do
{
printf("\n Enter the node to display the routing table : ");
scanf("%d",&src);
for(j=1;j<=n;j++)
{
if(src!=j)
{
if(a[src][j]!=0)
printf("\n The shortest path from %d to %d = %d \n",src,j,a[src][j]);
else
printf("\n There is no path from %d to %d \n",src,j);
}
}
printf("\n Do u want to continue(y/n) : ");
scanf("%s",&ch);
}while(ch!='n');
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
getch();
}

OUT PUT :

                                                                                                SHOWS  A  SUBNET

Enter the number of nodes = 6

Enter the distance between host : 1 and 2 ==> 2

Enter the distance between host : 1 and 3 ==> 5

Enter the distance between host : 1 and 4 ==> 1

Enter the distance between host : 1 and 5 ==> 2

Enter the distance between host : 1 and 6 ==> 10

Enter the distance between host : 2 and 1 ==> 2

Enter the distance between host : 2 and 3 ==> 3

Enter the distance between host : 2 and 4 ==> 2

Enter the distance between host : 2 and 5 ==> 3

Enter the distance between host : 2 and 6 ==> 8

Enter the distance between host : 3 and 1 ==> 5

Enter the distance between host : 3 and 2 ==> 3

Enter the distance between host : 3 and 4 ==> 3

Enter the distance between host : 3 and 5 ==> 1

Enter the distance between host : 3 and 6 ==> 5

Enter the distance between host : 4 and 1 ==> 1

Enter the distance between host : 4 and 2 ==> 2

Enter the distance between host : 4 and 3 ==> 3

Enter the distance between host : 4 and 5 ==> 1

Enter the distance between host : 4 and 6 ==> 3



Enter the distance between host : 5 and 1 ==> 6

Enter the distance between host : 5 and 2 ==> 4

Enter the distance between host : 5 and 3 ==> 1

Enter the distance between host : 5 and 4 ==> 1

Enter the distance between host : 5 and 6 ==> 2

Enter the distance between host : 6 and 1 ==> 10

Enter the distance between host : 6 and 2 ==> 8

Enter the distance between host : 6 and 3 ==> 5

Enter the distance between host : 6 and 4 ==> 3

Enter the distance between host : 6 and 5 ==> 2

ROUTING TABLE :


1
2
3
4
5
6
1
0
2
5
1
2
10
2
2
0
3
2
3
8
3
5
3
0
3
1
5
4
1
2
3
0
1
3
5
6
4
1
1
0
2
6
10
8
5
3
2
0

Enter the node to display the routing table : 2
The shortest path from 2 to 1 = 2
The shortest path from 2 to 3 = 3
The shortest path from 2 to 4 = 2
The shortest path from 2 to 5 = 3
The shortest path from 2 to 6 = 8
Do u want to continue (y/n) : n


ROUTING TABLE FOR 2 :


1
2
3
4
5
6
1
0
2
3
1
2
4
2
2
0
3
2
3
5
3
3
3
0
2
1
3
4
1
2
2
0
1
3
5
2
3
1
1
0
2
6
4
5
3
3
2
0


Implementation of Remote Method Invocation ( RMI )



/* Implementation of Remote Method Invocation ( RMI ) */

// RMIServerInter.java : A Simple RMI Server Interface Program

import java.rmi.*;

public interface RMIServerInter extends Remote
{
public double add(double d1,double d2) throws RemoteException;
public double sub(double d1,double d2) throws RemoteException;
public double mul(double d1,double d2) throws RemoteException;
public double div(double d1,double d2) throws RemoteException;
}

// RMIServerImpl.java : A Simple RMI Server Implementation Program

import java.rmi.*;
import java.rmi.server.*;

public class RMIServerImpl extends UnicastRemoteObject
implements RMIServerInter
{

public RMIServerImpl() throws Exception
{
}

public double add(double d1,double d2) throws RemoteException
{         
return d1+d2; 
}

public double sub(double d1,double d2) throws RemoteException
{
return d1-d2;
}

public double mul(double d1,double d2) throws RemoteException
{
return d1*d2;
}

public double div(double d1,double d2) throws RemoteException
{
return d1/d2;
}

}


// RMIServer.java : A Simple RMI Server Program

import java.rmi.*;
import java.net.*;

public class RMIServer
{
public static void main(String args[])
{
try
{
RMIServerImpl ad=new RMIServerImpl();
Naming.rebind("RMIServer",ad);
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
}
}
}


// RMIClient.java : A Simple RMI Client Program

import java.rmi.*;
import java.net.*;

public class RMIClient
{
public static void main(String args[])
{
try
{
String serverurl="rmi://localhost/RMIServer";
RMIServerInter ad=(RMIServerInter) Naming.lookup(serverurl);
System.out.println("The Sum of the values is : "+ ad.add(50,20));
System.out.println("The Difference of the values is : "+ad.sub(40,20));
System.out.println("The Product of the values is : "+ ad.mul(25,20));
System.out.println("The Divition of the values is : "+ ad.div(200,20));
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
}
}
}




OUTPUT :


RMIServerInter.java :

javac RMIServerInter.java

RMIServerImpl.java :

javac RMIServerImpl.java

RMIServer.java :

javac RMIServer.java

RMIClient.java :

javac RMIClient.java

Start RMI Registry :

start  rmiregistry

RMIServerImpl.class:

rmic RMIServerImpl

javac RMIClient.java

javac RMIServer.java

javac RMIServerImpl.java

javac RMIServerInter.java



RMIServer.java :

java RMIServer



RMIClient.java :

java RMIClient

The Sum of the values is : 70.0
The Difference of the values is : 20.0
The Product of the values is : 500.0
The Divition of the values is : 10.0

Implementation of PING Server Using Raw Socket



/* Implementation of PING Server Using Raw Socket */

// PingServer.java : A Simple Ping Server Program

import java.io.*;
import java.net.*;

class PingServer
{
public static void main(String args[])
{
try
{
String str;
System.out.print(" Enter the IP Address to be Ping : ");
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ping " + ip);
InputStream in=p.getInputStream();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=buf2.readLine())!=null)
{
System.out.println(" " + str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}


OUTPUT :


PingServer.java :


javac PingServer.java
java     PingServer

Enter the IP Address to be Ping : 192.168.1.5

Pinging 192.168.1.5 with 32 bytes of data:

Reply from 192.168.1.5: bytes=32 time<1ms TTL=128

Reply from 192.168.1.5: bytes=32 time<1ms TTL=128

Reply from 192.168.1.5: bytes=32 time<1ms TTL=128

Reply from 192.168.1.5: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.5:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms


Implementation of Talk Using TCP



/* Implementation of Talk Using TCP */

//  ChatServer.java : A Simple Talk Server Program

import java.io.*;
import java.net.*;

class ChatServer
{
public static void main(String args[]) throws Exception
{
try
{
int Port;
BufferedReader Buf =new BufferedReader(new
InputStreamReader(System.in));
System.out.print(" Enter the Port Address : " );
Port=Integer.parseInt(Buf.readLine());
ServerSocket sok =new ServerSocket(Port);
System.out.println(" Server is Ready To Receive a Message. ");
System.out.println(" Waiting ..... ");
Socket so=sok.accept();
if(so.isConnected()==true)
            System.out.println(" Client Socket is Connected Succecfully. ");
InputStream in=so.getInputStream();
OutputStream ou=so.getOutputStream();
PrintWriter pr=new PrintWriter(ou);
BufferedReader br1=new BufferedReader(new
InputStreamReader(System.in));
BufferedReader br2=new BufferedReader(new
InputStreamReader(in));
String str;
while(true)
{
System.out.println(" Mesage From Client : " + br2.readLine() );
System.out.print(" Enter the Message : ");
str=br1.readLine();
pr.println(str);
pr.flush();
}
}
              catch(Exception e)
              {
               System.out.println(" Error : " + e.getMessage());
              }
}
}



//  ChatClient.java : A Simple Talk Client Program

import java.io.*;
import java.net.*;

class ChatClient
{
public static void main(String args[]) throws Exception
{
try
{
int Port;
BufferedReader Buf =new BufferedReader(new
InputStreamReader(System.in));
System.out.print(" Enter the Port Address : " );
Port=Integer.parseInt(Buf.readLine());
Socket sok=new Socket("localhost",Port);
if(sok.isConnected()==true)
       System.out.println(" Server Socket is Connected Successfully. ");
InputStream in=sok.getInputStream();
OutputStream ou=sok.getOutputStream();
PrintWriter pr=new PrintWriter(ou);
BufferedReader br1=new BufferedReader(new
InputStreamReader(in));
BufferedReader br2=new BufferedReader(new
InputStreamReader(System.in));
String str;
while(true)
{
System.out.print(" Enter the Message : ");
str=br2.readLine();
pr.println(str);
pr.flush();
System.out.println(" Message From Server : " + br1.readLine());
}
}
catch(Exception e)
{
 System.out.println(" Error : " + e.getMessage());
}
}
}


OUTPUT :

ChatServer.java :

javac ChatServer.java
java     ChatServer

 Enter the Port Address : 1234
 Server is Ready To Receive a Message.
 Waiting .....
 Client Socket is Connected Succecfully.
 Mesage From Client : hi
 Enter the Message : Welcome To JCE
 Mesage From Client : I am Baran
 Enter the Message : Save the file and do the work
 Error : Connection reset

ChatClient.java :

javac ChatClient.java
java     ChatClient

 Enter the Port Address : 1234
 Server Socket is Connected Successfully.
 Enter the Message : hi
 Message From Server : Welcome To JCE
 Enter the Message : I am Baran
 Message From Server : Save the file and do the work
 Enter the Message : leave the lab