You are on page 1of 51

CS2307– NETWORK LAB

LABORATORY MANUAL (As per Anna University revised Syllabus for III Year B.Tech [IT])

STAFF MEMBERS DEPARTMENT OF INFORMATION TECHNOLOGY G.K.M. College of Engineering & Technology Chennai – 63

ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00

APPROVAL
The Manuel of CS2307 – Network Lab INFORMATION TECHNOLOGY

PREPARED BY,

APPROVAL BY,

JAYADEVI.P (LEC/IT) ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00

Mrs.C.SANKARI (HOD/IT)

CONTENTS
S.No 1. 2. 3. 4. 5. 6. 7. 8. Name of the Experiment IMPLEMENTATION OF TCP/IP ECHO TCP DATE/TIME CLIENT UDP ECHO SYSTEM UDP ECHO CLIENT & SERVER PROGRAMS USING RAW SOCKETS IMPLEMENTATION OF RAW SOCKET SIMULATION OF SLIDING WINDOW PROTOCOLS SIMULATION OF SLIDING WINDOW PROTOCOLS WITH CLIENT&SERVER PROGRAM USING RPC / RMI PERFORMANCE COMPARISION OF MAC PROTOCOLS IMPLEMENTING ROUTING PROTOCOLS STUDY OF TCP PERFORMANCE STUDY OF UDP PERFORMANCE

9. 10. 11. 12. 13.

PREPARED BY, JAYADEVI.P (LEC/IT)

APPROVAL BY, Mrs.C.SANKARI (HOD/IT)

ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00
EX No.: 1A Date:

IMPLEMENTATION OF TCP/IP ECHO
AIM: To implement the programming using TCP socket for Client and Server. ALGORITHM: 1.start the program. 2. Include necessary package in java. 3. To create a socket in client to server. 4. The client establishes a connection to the server. 5. The client accept the connection and send data to server and the server to replay the echo message to the client. 6. The client communicate the server to send the end of the message. 7. Stop the program.

PROGRAM: CLIENT import java.io.*; import java.net.*; public class Client { public final static int DEFAULT_PORT=10001; public static void main(String arg[])throws Exception { String str; System.out.println("Enter the string to echo : "); BufferedReader Stream=new BufferedReader(new InputStreamReader(system.in)); String hostname="127.0.01"; try {

System.out.println("connecting to "+hastname); Socket s=new Socket(hostname, DEFAULT_PORT); PrintStream out=new PrintStream(s.getOutputStream()); BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream())); out.println(str);

ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00
System.out.println("received for Server"+line); line=in.readLine(); } s.close(); catch(SocketException e) { System.out.println("Socket Error : "+e); } catch(UnknowHostException e) { System.out.println("in valid Host"); } catch(IOException e) { System.out.println("ioError : "+e); } } } OUTPUT: Enter the string to echo : Networks Connection to 127.0.01 Received from servernetworks

PROGRAM: SERVER import java.net.*; import java.io.*; import java.util.data.*; public class Server { public final static int DEFAULT_PORT=10001; public static void main(String arg[])throws Exception { int port=DEFAULT_PORT; try {

OutputStreamWriter out=new OutputStreamWriter(connection. } catch(IOException e) { } }}} catch(IOException e) { System. Socket connection=null. while(true) { try { connection=server.println(line+"was echod").println(e). out.accept().out. out. while(line==null) line=in.ServerSocket server=new ServerSocket(port).flash().getInputStream())). } catch(IOException e) { } finally { try { if(connection!=null) connection.close().write(line). connection. BufferedReader in=new BufferedReader(new InputStreamReader(connection.readLine().err. }}} OUTPUT: //accept connection from 1040 //networks was echoed .getOutputStream()).getPort()).out. String line=in. System.readLine(). System.println("Accept connection from" +connection.close().

public class Daytimeclient { public static void main(String[] args) { String hostname. PROGRAM: import java.: 1B TCP DATE/TIME CLIENT AIM: To write a program using TCP socket for Client.168. Using the object the port and address are declared.io. The listen and accept functions are executed. InputStream timestream=thesocket. } try { Socket thesocket= new Socket(hostname. Declare the variables and structure for the socket.getInputStream(). int c. Execute the client program. } else { hostname="192. ALGORITHM: Start the program.13)..*. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.*.net. while((c=timestream. import java. if(args. The socket is binded at the specified port.RESULT: Thus the above program is executed successfully and there output is verified. If the binding is successful it waits for client request.append((char) c). StringBuffer time=new StringBuffer().length>0) { hostname=args[0].13". .read())!=-1) time.1.

println("it is "+timestring+"at"+hostname).168.out.err. System.toString().1. } catch(UnknownHostException ex) { System.13 . } } } OUTPUT: It is wed jan 05 15:37:17 IST 2011 at 192.trim().err. } catch(IOException ex) { System.String timestring=time.println(ex).println(ex).

*.out. public static void main(String args[]) { int port=DEFAULT_PORT. public class Daytimeserver { public final static int DEFAULT_PORT=13.net.io.util. if(port<0||port>=65535) { System.length>0) { try { port=Integer. Declare the variables and structure.println("port must b/w 0 & 65535").*. Socket us created and connect function is executed. PROGRAM: import java. return. } } catch(NumberFormatException ex) { } . If the connection is successful then server sends the message. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.*. if(args. import java. import java. The date and time is printed at the client side.parseInt(args[0]).RESULT: Thus the above program for implementing TCP socket using CLIENT is Executed successfully and there output is verified.: 1B TCP DATE / TIME SERVER AIM: To write a program using TCP socket for SERVER. ALGORITHM: Start the program. Stop the program.

close(). } } } . while(true) { try { connection=server. connection. out. Socket connection=null.toString()+"\r\n").getOutputStream()). } catch(IOException ex) { } } } } catch(IOException ex) { System.write(now. Date now=new Date().out.close().} try { ServerSocket server= new ServerSocket(port). Writer out=new OutputStreamWriter(connection.println(ex). } catch(IOException ex) { } Finally { try { if(connection!=null) connection.flush(). out.accept().

ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 OUTPUT: Accepted .

The client accept the connection and to send the data from client to server and vice versa 5. PROGRAM: CLIENT import java. 4. Include necessary package in java 2.readLine().*.RESULT: Thus the above program for implementing TCP socket using SERVER is Executed successfully and there output is verified.0. 3.out. class Udpclient { public static void main(String args[])throws Exception { byte[] senddata=new byte[1024].io. InetAddress IPAddress=InetAddress. import java. The client communicate the server to send the end of the message 6. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No. BufferedReader infromuser=new BufferedReader(new InputStreamReader(System.equals("Q")) break.getByName("127. The client establishes a connection to the server. To create a socket in client to server. Stop the program.*. String data=infromuser.equals("q")||data.1"). .: 2A AIM: UDP ECHO SYSTEM To write a client-server application for chat using UDP. ALGORITHM: 1. DatagramSocket clientsocket=new DatagramSocket(). while(true) { System.0.println("Enter the data to send or type q or Q to quit").net. if(data.in)).

System.length).5000).getData().receive(receivepacket). DatagramPacket sendpacket=new DatagramPacket(senddata.*.close(). if(data.io. } } OUTPUT: Enter the data to send or type q or Q to quit Welcome to Network Lab Enter the data to send or type q or Q to quit q PROGRAM: SERVER import java. import java.println("Server is Waiting for client in port 5000"). else . class Udpserver { public static void main(String arg[])throws Exception { byte[] receivedata = new byte[1024].net. String data=new String(receivepacket. clientsocket. InetAddress IPAddress=receivepacket.getPort().else { senddata=data. socket1.IPAddress.senddata.out. receivepacket. } } clientsocket.0.equals("Q")) break. receivedata.0.getBytes().length. while(true) { DatagramPacket receivepacket = new DatagramPacket(receivedata.getAddress().equals("q")|| data.getLength()). byte[] senddata= new byte[1024].send(sendpacket).*. DatagramSocket socket1= new DatagramSocket(5000). recvport=receivepacket. int recvport.

0.System.1211) said : Welcome to Network Lab RESULT: Thus the above program for UDP Client and Server has been implemented .println("("+IPAddress+".2. } ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 OUTPUT: Server is waiting for client in port 5000 (/127.out."+recvport+")said :"+data).0.

*. } } public static void main(String args[])throws Exception { . System. The client communicate the server to send the end of the message 6.println(new String(p.receive(p). public static byte buffer[]= new byte[1024].successfully.getData(). Include necessary package in java 2.getLength())). 4. public static void MyClient()throws Exception { while(true) { DatagramPacket p=new DatagramPacket(buffer. class Udpclient { public static DatagramSocket ds. p. The client accept the connection and to send the data from client to server and vice versa 5. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No. buffer. Stop the program.: 2B Date: UDP ECHO CLIENT & SERVER AIM: To write a client-server application for chat using UDP ALGORITHM: CLIENT 1.out. ds. To create a socket in client to server.net.0. 3. PROGRAM : import java.length). The client establishes a connection to the server.

read(). break.777)).6.out. switch(c) { case -1: System. ds=new DatagramSocket(777). .net. MyClient(). public static byte buffer[]=new byte[1024].*. } } OUTPUT: c:\Program Files\java\jdk1.io..println("Server Quits"). case '\r': break.*.java c:\Program Files\java\jdk1.0_14\bin>javac udpclient. import java.0_14\bin>javac udpclient. PROGRAM : SERVER import java. case '\n': ds. while(true) { int c=System.getLocalHost().pos. return.out..send(new DatagramPacket(buffer.InetAddress. pos=0. class Udpserver2b { public static DatagramSocket ds.println("Client Press CTRL+c to quit"). public static void MyServer()throws Exception { int pos=0.in.6.java Client Press CTRL+C to Quit WELCOME TO NETWORK LAB.System.

MyServer().out.. ds=new DatagramSocket(888). } } OUTPUT: Server Ready Please type here.println("Server Ready \n Please type here.\n"). } } } public static void main(String args[])throws Exception { System.... WELCOME TO NETWORK LAB RESULT: Thus the above program a client-server application for chat using UDP was executed .default: buffer[pos++]=(byte)c.

System.out.out.getPort()). And using TCP\IP communication to enter the Source IP and port number and Target IP address and port number.*.println("The given data is"+new String(dp.out.getByName("Local host"). Using simple checksum process to check the process 5.getData())). public class datagramdata { public static void main(String args[])throws Exception { String s=" ".net.ia.: 3A Date: PROGRAMS USING RAW SOCKETS ` AIM : To implement programs using raw sockets (like packet capturing and filtering) ALGORITHM : 1. To define the packet length 3. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.port). try { InetAddress ia=InetAddress. byte[] data=s. Start the program and to include the necessary header files 2. Using TCP \IP communication protocol to execute the program 6. ACK 8. 7. Stop the program PROGRAM: import java.io.getAddress()+"on Port:"+dp. import java. The Raw socket () is created and accept the Socket ( ) and Send to ( ). int port=7.data.and successfully.println("There are"+dp. System.println("This Packet is addressed to"+dp.length. DatagramPacket dp=new DatagramPacket(data. .*. System. To declare the IP header structure using TCPheader 4.getBytes().getLength()+"bytes of data in the Packet").

0.1 on Port:7 The given data is Network There are 7 bytes of data in the Packet RESULT : Thus the Above programs using raw sockets was executed and successfully.out.0.println(e).} catch(UnknownHostException e) { System. . }}} OUTPUT: This Packet is addressed toLocalhost/127.

ACK 8. Stop the program PROGRAM: import java. } public String getEngine() { return this.: 3B Date: IMPLEMENTATION OF RAW SOCKET AIM : To implement programs using raw sockets (like packet capturing and filtering) ALGORITHM : 1.URLEncoder.UnsupportedEncodingException. import java.net. public QueryStringFormatter(String queryengine) { this.queryengine=queryengine. } public void addquery(String queryString. And using TCP\IP communication to enter the Source IP and port number and Target IP address and port number. Using simple checksum process to check the process 5. 7. public class QueryStringFormatter { private String queryengine. Start the program and to include the necessary header files 2.queryengine.String queryvalue)throws Exception { . To define the packet length 3. Using TCP \IP communication protocol to execute the program 6. The Raw socket () is created and accept the Socket ( ) and Send to ( ). To declare the IP header structure using TCPheader 4.io. private StringBuilder query=new StringBuilder().ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.

query.addquery("q".google.getEngine()+formatter."UTF-8")+"&").getqueryengine())."/").encode(queryvalue. System.com."xing chan&sham").addquery("newwindow".an/search?newwindow=%2F&q=xing+chan%26sham& RESULT : Thus the Above programs implementation of raw sockets was executed and successfully. } } OUTPUT: http://www. ISO/IT/MANUAL/NETWORK LAB-CS2307 .out.an/search"). } public String getqueryengine() { return "?"+query. formatter. } public static void main(String[] args)throws Exception { QueryStringFormatter formatter=new QueryStringFormatter("http://www. formatter.google.append(queryString+"="+URLEncoder.toString().com.println(formatter.

i++. r1=fopen("n. r2=fopen("op.window=4.txt". ALGORITHM: 1. int sel=0.Stop the program PROGRAM: #include<stdio.r=0.ACKNOWLEDGEMENT\n2.Start the program.i++) { while(choice==1) { printf("MENU\n0. for(i=0.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client.res=0.c".ISSUE:B REV:00 EX No.choice=1.Get the frame size from the user 3. printf("INITIAL WINDOW SIZE IS : 4\n").str[100].i<len."w").EXIT").*r2. 4.h> FILE *r1.SEND\n1. .h> #include<stdlib.h> #include<string.To create the frame based on the user request.len. char a. int main() { int count=0.sig=0. printf("\n Enter Your Choice : "). } len=1.n."r"). while((a=getc(r1))!=EOF) { str[i]=a. 6. 5.: 4A SIMULATION OF SLIDING WINDOW PROTOCOLS AIM: To write a C program to perform sliding window.i=0.To send frames to server from the client side. 2.

window)... printf("\n NO.scanf("%d". r=0. window--.&res). count=0. } .OF CHARACTER SENT IS : %d". } break.. } } i++.str[i]).. case 2: break.. } else { printf("\n ACKNOWLEDGING.i+1). break. } res=0. window=4. printf("\n PRESS 1 FOR ACKNOWLEDGEMENT"). case 1: if(r==0) { printf("\n NO DATA SENT YET"). printf("\n WINDOW SIZE IS RESTORED OF 4").window).&sel). window=4. scanf("%d". if(window==0) { printf("\n WINDOW SIZE IS NULL"). while(res!=1) { printf("\n CANNOT SEND DATA FURTHER").."%c".. sig=1. printf("\n THE SIZE OF WINDOW IS %d"."). fprintf(r1.. switch(sel) { case 0: if(window!=0) { r=1. sig=0.. printf("\n THE WINDOW SIZE IS %d".

fclose(r2).EXIT Enter Your Choice : 1 .OF CHARACTER SENT IS : 1 THE SIZE OF WINDOW IS 3 PRESS 1 TO CONTINUE 2 TO EXIT1 MENU 0..ACKNOWLEDGEMENT 2...printf("\n PRESS 1 TO CONTINUE 2 TO EXIT")..1C } } fclose(r1).c [3IT16@localhost ~]$ .. scanf("%d"...ACKNOWLEDGEMENT 2.out INITIAL WINDOW SIZE IS : 4 MENU 0. WINDOW SIZE IS RESTORED OF 4 PRESS 1 TO CONTINUE 2 TO EXIT1 MENU 0./a.ACKNOWLEDGEMENT 2.SEND 1..EXIT Enter Your Choice : 1 ACKNOWLEDGING.EXIT Enter Your Choice : 0 NO. } OUTPUT: [3IT16@localhost ~]$ cc sliding.SEND 1..&choice).SEND 1.

.OF CHARACTER SENT IS : 2 THE SIZE OF WINDOW IS 3 PRESS 1 TO CONTINUE 2 TO EXIT1 MENU 0..ACKNOWLEDGEMENT 2...EXIT Enter Your Choice : 1 ACKNOWLEDGING.SEND 1.SEND 1.ACKNOWLEDGEMENT 2.OF CHARACTER SENT IS : 3 THE SIZE OF WINDOW IS 3 PRESS 1 TO CONTINUE 2 TO EXIT RESULT: Thus the above program sliding window protocol was executed and successfully ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 .. WINDOW SIZE IS RESTORED OF 4 PRESS 1 TO CONTINUE 2 TO EXIT1 MENU 0.NO DATA SENT YET PRESS 1 TO CONTINUE 2 TO EXIT1 MENU 0..ACKNOWLEDGEMENT 2...SEND 1.EXIT Enter Your Choice : 0 NO..EXIT Enter Your Choice : 0 NO.

con. 11.h> #include<stdlib.: 4B Date: SIMULATION OF SLIDING WINDOW PROTOCOLS WITH CLIENT AIM: To write a C program to perform sliding window.EX No. 8.h> #include<unistd. if((sd==socket(AF_INET. cli.Start the program.sizeof(cli)). ALGORITHM: CLIENT 7. cli. } .IPPROTO_TCP))==-1) { printf("\n socket problem").To create the frame based on the user request.h> #include<sys/types.sin_family=AF_INET.h> #include<string.ack[3].To send frames to server from the client side.Stop the program PROGRAM: #include<stdio. } bzero((char*)&cli. if(con==-1) { printf("\n connection errir").sizeof(cli)).sin_port=htons(port). printf("ENTER PORT NO").s_addr=htonl(INADDR_ANY).Get the frame size from the user 9.&port). return 0.i.SOCK_STREAM. con=connect(sd.(struct sockaddr*)&cli. return 0.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 10.sin_addr.h> #include<sys/socket.h> int main() { int sd. 12. char content[30]. cli. struct sockaddr_in cli. scanf("%d".port.h> #include<netinet/in.

content).30.ack).0)..ack. goto ph."EOF")!=0) { printf("Received from sender:Frame%s\n". } printf("\n BYE.30.5. ph: printf("\nAcknowledgement(ACK/NAK):").0)."NAK")==0)) { printf("\nNot a valid acknowledgement.0).content...content.. if(!(strcmp(ack. while(strcmp(content.")...."ack")==0||strcmp(ack.use ACK or NAK").... } OUTPUT: ENTER PORT NO: 4500 Received from sender: Frame 0 Acknowledgement(ACK/NAK) : ACK Received from sender : Frame 1 Acknowledgement(ACK/NAK) : ACK Received from sender : Frame 0 Acknowledgement(ACK/NAK) : ACK Received from sender : Frame 0 Acknowledgement(ACK/NAK) : ACK Received from sender : Frame 1 Acknowledgement(ACK/NAK) : ACK Received from sender : Frame 0 Acknowledgement(ACK/NAK) : ACK Bye… ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 .i=recv(sd. i=recv(sd. return 0. scanf("%s". close(sd). } send(sd.

nsd.sizeof(ser)).(struct sockaddr*)&ser. Get the frame size from the user To create the frame based on the user request. } i=sizeof(cli).port busy.ALGORITHM: SERVER Start the program. ser.sin_addr. bi=bind(sd.count=0.h> #include<stdlib. if(bi==-1) { printf("\nbind error. char ack[5]. if((sd=socket(AF_INET.bi.i. To send frames to server from the client side. ser.prev_frame=0.sin_family=AF_INET.sizeof(ser)). printf("\nport addressis %d:". bzero((char*)&cli.cli. .h> #include<sys/socket.please change port in client & server").buff[30]. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client.IPPROTO_TCP))==-1) { printf("\n socket problem").&port).port. struct sockaddr_in ser.5). ser.s_addr=htonl(INADDR_ANY).frame. printf("\nenter port no:").port).h> #include<string.h> #include<sys/types. scanf("%d". } printf("\nsocket created").SOCK_STREAM. return 0. return 0. Stop the program PROGRAM: #include<stdio.sin_port=htons(port).r.h> main() { int sd. listen(sd.h> #include<netinet/in.h> #include<unistd.

prev_frame).5. } else if(strcmp(ack. goto ph.ack."NAK")==0) { printf("\n NAK:so again sending the previous frame"). } printf("\n connection accepted")."ACK")==0) { count++.((struct sockaddr*)&cli)..0)."%d".buff. send(nsd. return 0.sizeof(buff).nsd=accept(sd.0). while(count<5) { ph: printf("\n sending FRAME %d to the receiver.30. if(nsd==-1) { printf("\n check the description parameter"). Connecting accepted Sending FRAME 0 to the Receiver… Sending FRAME 1 to the Receiver… Sending FRAME 0 to the Receiver… NAK : so again sending the previous Frame… Sending FRAME 0 to the Receiver… Sending FRAME 1 to the Receiver… Sending FRAME 0 to the Receiver… Bye… .&i). } OUTPUT : Socket created ENTER THE PORT NO: 4500 Port Address is 4500 . .prev_frame).". r=recv(nsd.. snprintf(buff."nak")==0||strcmp(ack. if(prev_frame==0)prev_frame=1."ack")==0||strcmp(ack. if(strcmp(ack. else prev_frame=0.

RESULT: Thus the above program sliding window protocol with Client & Server was executed successfully. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 .

rmi.println("the first number is"+args[1]). AddServerIntf addServerIntf=(AddServerIntf)Naming.d2)).println("Exception:"+e).To Execute Start RMI registry 7. public class AddClient { public static void main(String args[]) { try { String addServerURL="rmi://"+args[0]+"/AddServer".valueOf(args[2]).Start the program and to include necessary packages 2. double d2=Double.println("the Second number is"+args[2]).out.valueOf(args[1]). } } } .Finally to call and compile all the sub program 6. System.lookup(addServerURL).Stop the program PROGRAM: ADD CLIENT: import java.Using Add server() to implement and Call the Add server impl 4.: 5 Date: PROGRAM USING RPC / RMI AIM : To implement the program using RMI ALGORITHM : 1.out.Using Add client to get the two values 3. System.Using public interface to call the program in remotely 5. } catch(Exception e) { System. System. double d1=Double.println("the sum is "+addServerIntf.*.out.add(d1.EX No.out.doubleValue( ).doubleValue().

} catch(Exception e) { System.rebind("AddServer".double d2)throws RemoteException.double d2)throws RemoteException { return d1+d2. Naming.addServerImpl).net. public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { public AddServerImpl()throws RemoteException { } public double add(double d1.rmi.ADD SERVER import java.rmi.*. public interface AddServerIntf extends Remote { double add(double d1.out.*. } } } ADD SERVERIMPL: import java.rmi. import java. import java. public class AddServer { public static void main(String args[]) { try { AddServerImpl addServerImpl=new AddServerImpl().*.server.*. } } ADDSERVERINTF: import java.println("Exception :"+e). } .rmi.*.

6.0_14\bin\RMI>javac *.0_14\bin\RMI>java AddServer c:\Program Files\java\jdk1.0 RESULT: Thus the Above program RMI was executed and sucessfully.OUTPUT: c:\Program Files\java\jdk1.java c:\Program Files\java\jdk1.0_14\bin\RMI>java AddClient localhost 2 4 the first number is 2 the second number is 4 the sum is 6.0_14\bin\RMI>rmic AddServerImpl c:\Program Files\java\jdk1. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.6.6.: 6 .0_14\bin\RMI>java AddServer c:\Program Files\java\jdk1.0_14\bin\RMI>start rmiregestery c:\Program Files\java\jdk1.6.6.6.

Copy the IPAddress from sockaddr_in structure to arpreq structure using miscopy () system call. PROGRAM: #include<unistd. Get the IPAddress of the system as command line argument.char *argv[]) { int sd. 8.sin_family=AF_INET. Initialize the arpreq structure initially to zero. 7. Include necessary header files. 2. 6. unsigned char *ptr.h> #include<netdb.h> #include<stdio. Display the IPAddress and MAC address in the standard output. 4. 5.Date: PERFORMANCE COMPARISION OF MAC PROTOCOLS AIM: To get the MAC or Physical address of the system using Address Resolution Protocol. Calculate the MAC address for the given IPAddress using ioctl() system call. ALGORITHM: 1.h> #include<sys/types.h> #include<sys/socket. Create a socket of type SOCK_DGRAM.h> #include<stdlib.argv[1]). sin.h> #include<sys/ioctl. Check whether the given IPAddress is valid.sin_addr)==0) { printf("IP address Entered%s is not valid\n".h> #include<arpa/inet.h> #include<netinet/in.h> #include<net/if_arp.&sin. } . if(inet_aton(argv[1].h> int main(int argc. struct arpreq myarp={{0}}. exit(0). struct sockaddr_in sin={0}. 3.

30.memcpy(&myarp.c [3IT16@localhost ~]$ ]$ .30.50.SOCK_DGRAM.arp_pa)).128 = 0:13:20:13:A3:F2 RESULT: Thus the MAC address was generated for IP address using ARP protocol is executed successfully. exit(0).SIOCGARP.out 131. } ptr=&myarp.0).sizeof(myarp.&myarp)==1) { printf("No entry in ARP cache for%s".argv[1]). printf("MAC address for%s".*(ptr+5)).arp_dev."eth0").&sin.128 MAC Address for 131. if(ioctl(sd. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.*(ptr+1).arp_ha.*(ptr+2).50. sd=socket(AF_INET.*(ptr+3). return(0). printf("%x%x%x%x%x%x\n".*(ptr+4). } OUTPUT: [3IT16@localhost ~]$ cc arp.argv[1]).*ptr./a.sa_data[0].arp_pa. strcpy(myarp.: 7 .

i<n. 5. int i.k.Repeat step 6 to step 8 for n-l nodes.Choose the node that has not been included whose distance is minimum and include that node.&n).Read the cost matrix for the path from each node to another node. of nodes n 2.i+1.j+1). for(i=0.i++) { for(j=0. scanf("%d".i<n.i++) . scanf("%d".%d:". 6.b[10][10].j.h> int main() { int n.&a[i][j]). 3.Date: IMPLEMENTING ROUTING PROTOCOLS AIM: To simulate the Implementing Routing Protocols using border gateway protocol(BGP) ALGORITHM: 1.j<n.Take the minimum value as the new distance.Compute D of a node which is the distance from source to that corresponding node.Initialize SOURCE to 1 and include 1 4.For every other node not included compare the distance directly from the source with the distance to reach the node using the newly included node 8.j++) { printf("\n Enter the distance between the host %d . int a[10][10].h> #include<conio.Read the no. 7. } } for(i=0. 9.Print all the nodes with shortest path cost from source node PROGRAM: #include <stdio. printf("\n Enter the number of nodes:").

} printf("\n"). if(i==j) { b[i][j]=0.j++) { printf("%d\t". } getch().k<n.b[i][j]).k++) { for(i=0.j++) { if(a[i][j]>a[i][k]+a[k][j]) { a[i][j]=a[i][k]+a[k][j].j<n. } OUTPUT: [3IT16@localhost ~]$ cc bgp. } printf("\n").j++) { printf("%d\t". } } } printf("\n The output matrix:\n").i<n.j++) { b[i][j]=a[i][j].c .j<n.i++) { for(j=0.a[i][j]). } } } } for(i=0.i<n. } for(k=0.i++) { for(j=0.i++) { for(j=0. for(i=0.{ for(j=0.j<n.i<n.j<n.

2:1 Enter the distance between the host 4 ./a.out Enter the number of nodes:4 Enter the distance between the host 1 .1:6 Enter the distance between the host 3 .3:4 Enter the distance between the host 3 .4:2 Enter the distance between the host 4 .OSPF .2:1 Enter the distance between the host 3 .3:6 Enter the distance between the host 1 .3:8 Enter the distance between the host 4 .4:2 5 2 6 5 9 1 1 1 6 8 4 8 4 3 2 2 The output matrix: 0 2 3 3 5 0 1 1 6 8 0 8 4 3 2 0 RESULT: Thus the above program to simulate the Implementing Routing Protocols using border gateway protocol was executed and successfully ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.4:3 Enter the distance between the host 3 .2:1 Enter the distance between the host 2 .2:9 Enter the distance between the host 1 .1:2 Enter the distance between the host 2 .1:5 Enter the distance between the host 1 .: 8 Date: IMPLEMENTING ROUTING PROTOCOL .3:8 Enter the distance between the host 2 .[ 3IT16@localhost ~]$ .4:4 Enter the distance between the host 2 .1:5 Enter the distance between the host 4 .

&n).i.j. display(). . of nodes n 2. scanf("%d". getdata().Print all the nodes with shortest path cost from source node PROGRAM: #include<stdio.For every other node not included compare the distance directly from the source with the distance to reach the node using the newly included node 8. ALGORITHM: 1. clrscr(). 5.Read the no.Choose the node that has not been included whose distance is minimum and include that node. void display(). Compute D of a node which is the distance from source to that corresponding node. void main() { void getdata(). printf("\n\n PROGRAM TO FIND SHORTEST PATH BETWEEN TWO NODES\n").h> int a[5][5].AIM: To simulate the OPEN SHORTEST PATH FIRST routing protocol based on the cost assigned to the path.n.Take the minimum value as the new distance. shortest(). 9.Repeat step 6 to step 8 for n-l nodes. } void getdata() { clrscr(). getch().h> #include<conio. 7. 3. 6.Initialize SOURCE to 1 and include 1 4. void shortest().Read the cost matrix for the path from each node to another node. printf("\n\nENTER THE NUMBER OF HOST IN THE GRAPH\n").

} OUTPUT: [3IT16@localhost ~]$ cc ospf. for(i=0. scanf("%d".i<n.%d): ".j++) if(i!=j) { printf("\n SHORTEST PATH IS : (%d.i++) { a[i][j]=0. printf(" \n\nASSIGN THE HIGHEST DISTANCE VALUE 1000 \n"). if(a[i][j]==0) a[i][j]=1000.j.i<n.c [ 3IT16@localhost ~]$ .printf("\n\nIF THERE IS NO DIRECT PATH \n").k.i++) for(j=0. for(k=0.i+1. for(j=0.%d)--%d\n".j.i++) for(j=0.j++) { if(a[i][k]+a[k][j]<a[i][j]) a[i][j]=a[i][k]+a[k][j]. } } } } void shortest() { int i.j+1).a[i][j]).&a[i][j]).i+1.k++) for(i=0.j+1. } getch().j<n.j++) { if(i!=j) { printf("\n\nENTER THE DISTANCE BETWENN (%d. for(i=0.i<n.j<n. } } void display() { int i./a.k<n.j<n.out .

1): 1 Enter the Distance Between (4.2): 3 Enter the Distance Between (3.1)--3 Shortest path is: (3.2)--2 Shortest path is: (1.4): 1 Enter the Distance Between (3.1): 2 Enter the Distance Between (2.3)--2 RESULT: Thus the above program to simulate the Implementing Routing Protocols using open shortest path first (OSPF) was executed and successfully.4)--1 Shortest path is: (3. ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No.2): 1 Enter the Distance Between (4.Enter the Distance Between (2.2)--3 Shortest path is: (3.3): 2 Shortest path is: (1.1)--2 Shortest path is: (2.1)--1 Shortest path is: (4.: 9 Date: STUDY OF TCP PERFORMANCE .4): 2 Enter the Distance Between (4.4)--1 Shortest path is: (2.4)--2 Shortest path is: (4.2)--1 Shortest path is: (4.3)--3 Shortest path is: (1.3)--3 Shortest path is: (2.3): 3 Enter the Distance Between (2.1): 3 Enter the Distance Between (3.

This field is also used within the flow-control structure to allow the association of a data packet with its corresponding acknowledgement. allowing a sender to estimate the current round-trip time across the network. The TCP Protocal Header The TCP header structure. This article draws on material published in the Internet Performance Survival Guide [1]. shown in Figure 1. Figure 1: The TCP/IP Datagram . TCP provides a reliable data-transfer service. and is used for both bulk data transfer and interactive data applications. The sequence number does not start at an initial value of 1 for each new TCP connection. uses a pair of 16-bit source and destination Port addresses. TCP is the major transport protocol in use in most IP networks.AIM: To study of TCP Performance of TCP. looking at what makes a TCP session perform reliably and well. UDP is a lightweight protocol that allows applications to make direct use of the unreliable datagram service provided by the underlying IP service. INTRODUCTION: The Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP) are both IP transport-layer protocols. which identifies the sequence number of the first data octet in this packet. and supports the transfer of over 90 percent of all traffic across the public Internet today. In this article we examine TCP in further detail. or applications that support real-time communications. the performance of this protocol forms a significant part of the total picture of service performance for IP networks. UDP is commonly used to support applications that use simple query/response transactions. The next field is a 32-bit sequence number. because the initial value is intended to prevent delayed data from an old connection from being incorrectly interpreted as being valid within a current connection. the selection of an initial value is critical. The sequence number is necessary to ensure that arriving packets can be ordered in the sender?s original order. Given this major role for TCP.

ACK is used to indicate whether the acknowledgment field is valid. The TCP checksum is applied to a synthesized header that includes the source and destination addresses from the outer IP datagram. measured in octets. when added to the sequence number. Many options can be carried in a TCP header. this option should be used with path MTU discovery to establish a segment size that can be passed across the connection without fragmentation. The final field in the TCP header is the urgent pointer. indicates the sequence number of the final octet of urgent data if the urgent flag is set. passed to the remote end of the connection. an essential attribute of a high-performance data flow. URG is used to indicate whether the urgent pointer is valid. . The window field is a 16-bit count of available buffer space. In a robust implementation of TCP. This option is used only in the initial SYN packet (the initial packet exchange that opens a TCP connection). The acknowledgment sequence number is actually one greater than that of the last octet correctly received at the local end of the connection. It is intended to inform the remote end of the maximum segment size. It is added to the acknowledgment sequence number to indicate the highest sequence number the receiver can accept. The data offset field indicates the number of four-octet words within the TCP header. SYN (for synchronize ) is used within the connection startup phase. that the sender is willing to receive on the TCP connection.The acknowledgment sequence number is used to inform the remote end of the data that has been successfully received. It sets both the maximum receive segment size and the maximum size of the advertised TCP window. Those relevant to TCP performance include: • Maximum-receive-segment-size option : This option is used when the connection is being opened. Six single bit flags are used to indicate various conditions. which. RST is used to reset the connection. PSH is set when the sender wants the remote application to push this data to the remote application. and FIN (for finish ) is used to close the connection in an orderly fashion.

The SACK option allows the receiver to modify the acknowledgment field to describe noncontinuous blocks of received data. Use of the window-scale option allows the TCP sender to effectively adapt to high-bandwidth. no corresponding bandwidth delay product discovery allows the reliable automated setting of the windowscale option [3]. by allowing more data to be held in flight. The default TCP acknowledgment behavior is to acknowledge the highest sequence number of in-order bytes. SACK is an acronym for selective acknowledgment . and can be sent in a packet only with the SYN flag. This option allows the window size advertisement to be right-shifted by the amount specified (in binary arithmetic.535 bytes per round-trip interval. • SACK-permitted option and SACK option : This option alters the acknowledgment behavior of TCP. the maximum window size that can be advertised is 65. For high-speed. this performance limitation is a significant factor. The SACKpermitted option is offered to the remote end during TCP setup as an option to an opening SYN packet. Without this option. regardless of available network capacity. The limit of TCP transfer speed is effectively one window size in transit between the sender and the receiver. Any robust high-performance implementation of TCP should negotiate these parameters at the start of the TCP session. high-delay network paths. which can exacerbate a congestion condition that may have been the cause of the original packet loss. This default behavior is prone to cause unnecessary retransmission of data.535 bytes (the maximum value obtainable in a 16-bit field). ensuring the following: that the session is using the largest possible IP packet size that can be carried without fragmentation. that the window sizes used in the transfer . so that the sender can retransmit only what is missing at the receiver's end [4]. long-delay networks. This option is negotiated at the start of the TCP connection. a right-shift corresponds to a multiplication by 2). The maximum window size with this option is 2 30 bytes. because it limits the transfer rate to at most 65. The SACK option permits selective acknowledgment of permitted data.• Window-scale option : This option is intended to address the issue of the maximum window size in the face of paths that exhibit a high-delay bandwidth product. Note that while an MTU discovery process allows optimal setting of the maximum-receive-segment-size option.

are adequate for the bandwidth-delay product of the network path. • The local end responds with an ACK of this remote sequence number. using a SYN packet. The protocol interaction to support this is indicated in Figure 3. ensuring that both sides of the connection have an unambiguous understanding of the sequence number space of the remote side for this session. The operation of the connection is as follows: • The local system sends the remote end an initial sequence number to the remote port. The connection is opened. • The remote system responds with an ACK of the initial sequence number and the initial sequence number of the remote end in a response SYN packet. Interactive TCP Interactive protocols are typically directed at supporting single character interactions. Figure 3: Interactive Exchange . as is its echo. The performance implication of this protocol exchange is that it takes one and a half round-trip times (RTTs) for the two systems to synchronize state before any data can be sent. TCP Operation The first phase of a TCP session is establishment of the connection. and that selective acknowledgment can be used for rapid recovery from line-error conditions or from short periods of marginally degraded network performance. where each character is carried in a single packet. The operation of this algorithm is shown in Figure 2. This requires a three-way handshake.

how does a TCP sender know that it is sending at a rate greater than the network can sustain? The answer is that this is shown by data packets being dropped by the network. when the rate exceeds the remembered value of the onset of congestion as recorded in ssthresh. This SMSS value is based on the receiver's maximum segment size. or IW) is set to that of the Sender Maximum Segment Size (SMSS) value. in the absence of other information. obtained during the SYN handshake. the MTU of the sending interface.TCP Slow Start The starting value of the cwnd window (the Initial Window. The sender then enters a flow-control mode termed Slow Start . 536 bytes. . Addressing the last condition. or. How does TCP know when to stop this increase? This slow-start rate increase stops when the congestion window exceeds the receiver's advertised window. or when the rate is greater than the network can sustain. In this case. TCP has to undertake many functions: • The packet loss has to be detected by the sender. the discovered path MTU (if used). Packet Loss Slow Start attempts to start a TCP session at a rate the network can support and then continually increase the rate.

poor (or no) use of path-MTU discovery. imprecise use of protocol-required timers. and those that appear to be highly productive areas of further research and investigation [1] . Tuning TCP How can the host optimize its TCP stack for optimum performance? Many recommendations can be considered. Larger buffers at the sender and the receiver assist the sender in adapting more efficiently to a wider diversity of network paths by permitting a larger volume of traffic to be placed in flight across the end-to-end path.• • The missing data has to be retransmitted. combined with a selective repeat-transmission policy. It is unclear whether network ingress-imposed Quality-of-Service (QoS) structures will adequately compensate for such implementation deficiencies. no use of window scaling and SACK. The following suggestions are a combination of those measures that have been well studied and are known to improve TCP performance. • Implement a TCP Selective Acknowledgment (SACK) mechanism : SACK. Many of these performance pathologies exist because of poor implementations of TCP flow-control algorithms. inadequate buffers within the receiver. • Support TCP ECN negotiation : ECN enables the host to be explicitly informed of conditions relating to the onset of congestion without having to infer such a condition . and very coarse-grained timers. The sending data rate should be adjusted to reduce the probability of further packet loss. • Use a good TCP protocol stack : Many of the performance pathologies that exist in the network today are not necessarily the byproduct of oversubscribed networks and consequent congestion. The conclusion is that attempting to address the symptoms is not the same as curing the disease. • Implement larger buffers with TCP window-scaling options : The TCP flow algorithm attempts to work at a data rate that is the minimum of the delay-bandwidth product of the end-to-end network path and the available buffer space of the sender. A good protocol stack can produce even better results in the right environment. no support for fast-retransmit flow recovery. can help overcome the limitation that traditional TCP experiences when a sender can learn only about a single lost packet per RTT.

from the reserve stream of ACK packets from the receiver. • Use a host platform that has sufficient processor and memory capacity to drive the network . ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 EX No. The host can react to such a condition promptly and effectively with a data flow-control response without having to invoke packet retransmission. is an unreliable connectionless protocol that does not guarantee accurate or unduplicated delivery of data. where the peak application load on the server drives the platform into a state of memory and processor exhaustion. The Transport Control Protocol (TCP). is a reliable connection-oriented protocol that allows datastreams coming from a machine connected to the Internet to be received without error by any other machine on the Internet.: 10 Date: STUDY OF UDP PERFORMANCE AIM: To write the study excersize for the Performance of UDP. even though the network itself has adequate resources to manage the traffic load. Why do games use UDP? . This is a condition that can be observed in large or very popular public Web servers. The highest-quality service network and optimally provisioned access circuits cannot compensate for a host system that does not have sufficient capacity to drive the service load. Introduction Most network games use the User Datagram Protocol (UDP) as the underlying transport protocol. RESULT: Thus the above program to study of TCP Performance is executed successfully. which is what most Internet traffic relies on. UDP however.

UDP is described in RFC 768. What is more important to gaming applications is the prompt delivery of data. A study carried out in the University of Waikato in New Zealand suggests that UDP traffic has a negative effect on TCP throughput. UDP allows applications to send IP datagrams to other applications without having to establish a connection and than having to release it later. It includes the 8-byte header and the data to be sent. A zero is inserted into it if it is not used. UDP allows gaming application programs to send messages to other programs with the minimum of protocol mechanism. UDP affects TCP throughput in much the same way as . Packets are simply transmitted one after another with complete disregard to event of the receiver being flooded. which increases the speed of communication. Games do not rely upon ordered reliable delivery of data streams. The UDP Length field shows the length of the datagram in octets.TCP has proved too complex and too slow to sustain real-time game-play. The effects of UDP As mentioned before the majority of the traffic on the Internet relies on TCP. The source port indicates the port of the sending process and unless otherwise stated it is the port to which a reply should be sent to. Fields The source and destination ports identify the end points within the source and destination machines. there are concerns about the effects that UDP will have on TCP traffic. UDP is now seen as being aggressive to 'network friendly applications deploying adaptive congestion control'. The UDP segment shown above consists of an 8-byte header followed by the data octets. and with most of these games using UDP. This is because UDP does not rely on acknowledgements to signal successful delivery of data. With the explosive increase in the amount of gaming taking place on the Internet. While TCP implements a form of flow control to stop the network from flooding there is no such concept in UDP.

and Terminal Access Controller Access Control System. you must specify the ip helper-address command on every interface on every router that receives a broadcast that needs to be forwarded. which must be analyzed and discarded. Boot Protocol. On Router A and Router B. and Router B receives each broadcast sent by Router A three times. you must specify them as arguments to the ip forward-protocol udp command. To enable forwarding for other ports. As more segments and devices are added to the network. a second ip helper address command must be applied to every router interface that receives UDP broadcasts. When IP helper addressing is used in this type of topology. one for each segment. The study shows that UDP behaves in much the same way regardless of what application is running it. more ip helper address commands are required to reach them. IP helper addressing in not the optimal solution for this type of topology because each router receives unnecessary broadcasts from the other router. Time service. the ip forward-protocol udp command enables forwarding for ports associated with the following protocols: Trivial File Transfer Protocol. NetBIOS Name Server. By default. you must use the ip forward-protocol udp global configuration command to enable the UDP forwarding. NetBIOS Datagram Server. To send UDP broadcasts bidirectionally in this type of topology.digitized speech over IP does. As more segments are added to the network. Router A receives each broadcast sent by Router B three times. Implementing IP Helper Addressing Note Regardless of whether you implement IP helper addressing or UDP flooding. no more than one router can be configured to forward UDP broadcasts (unless the receiving applications can handle duplicate broadcasts). the routers become overloaded with unnecessary traffic. Domain Name System. To configure helper addressing. Implementing IP Helper Addressing IP helper addressing is a form of static addressing that uses directed broadcasts to forward local and all-nets broadcasts to desired destinations within the internetwork. When each broadcast is received. . IP helper addresses can be configured to move data from the TIC server network to the trader networks. so the administration of these routers becomes more complex over time. This restriction limits redundancy in the design and can be undesirable in some implementations. Implementing IP Helper Addressing In this case. This is because duplicate packets arrive on the trader network. one for each segment. the router must analyze it and determine that the broadcast does not need to be forwarded. Note.

ISO/IT/MANUAL/NETWORK LAB-CS2307 ISSUE:B REV:00 . that bidirectional traffic in this topology significantly impacts router performance.too. RESULT: Thus the above program to study of TCP Performance is executed successfully.