CS9216

NETWORKING LAB(C/C++)

LIST OF EXPERIMENTS 1. Socket Programming a. TCP Sockets b. UDP Sockets c. Applications using Sockets 2. Simulation of Sliding Window Protocol 3. Simulation of Routing Protocols 4. Development of applications such as DNS/ HTTP/ E – mail/ Multi user Chat 5. Simulation of Network Management Protocols 6. Study of Network Simulator Packages – such as opnet, ns2, etc.

HARDWARE REQUIREMENTS Processor Hard disk RAM Monitor :Pentium IV :20 GB :256 MB :VGA and high resolution monitor

SOFTWARE REQUIREMENTS Operating system :LINUX Language :C/C++

Ex.no:1 Date:
AIM

CLIENT-SERVER CHAT PROGRAM USING TCP

To write a C program for implementing Client-Server Chat using TCP.

ALGORITHM SERVER
Step 1: Start the program. Step 2: Create an unnamed socket for the server using the parameters AF_INET as domain and the SOCK_STREAM as type. Step 3: Name the socket using bind( ) system call with the parameters server_sockfd and the server address(sin_addr and sin_sport). Step 4: Create a connection queue and wait for clients using the listen( ) system call with the number of clients request as parameters. Step 5: Accept the connection using accept( ) system call when client requests for connection. Step 6: Get the message which has to be sent to the client and check that it is not equal to ‘Bye’. Step 7: If the message is not equal to ‘Bye’ then write the message to the client and Goto step 6. Step 8: If the message is ‘Bye’ then terminate the Process. Step 9: Stop the program execution.

CLIENT
Step 1: Start the program. Step 2: Create an unnamed socket for client using socket( ) system. Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type. Step 4: Name the socket using bind( ) system call. Step 5: Now connect the socket to server using connect( ) system call. Step 6: Read the message from the server socket and compare it with ‘Bye’. Step 7: If the message is not equal to ‘Bye’ then print the message to the server output device and repeat the steps 6 & 7. Step 8: Get the message from the client side. Step 9: Write the message to server sockfd and goto step 4. Step 10:If the message is equal to ‘Bye’then print good bye message and terminate the process. Step 11:Stop the process.

printf("%s". listen(sd.0). else printf("\n Binded\n").20.rcvmsg. scanf("%d".sizeof(servaddr)). sd=socket(AF_INET. else printf("Accepted\n").sin_family=AF_INET.sin_addr.SOCK_STREAM.cliaddr. sendmsg[len-1]='\0'. .&sport).5).0).s_addr=htonl(INADDR_ANY).sin_port=htons(sport). nsd=accept(sd. if(sd2<0) printf(" Can't Bind\n").CLIENT SERVER CHAT USING TCP SERVER #include<stdio. if(nsd<0) printf("Can't Accept\n"). struct sockaddr_in servaddr.&clilen). servaddr. char sendmsg[20].sport. printf("Enter the Server port").stdin).rcvmsg[20]. else printf("Socket is Created\n"). len=strlen(sendmsg). if(sd<0) printf("Can't Create \n").rcvmsg).h> main() { int sd.sd2.len. fgets(sendmsg.clilen.nsd. servaddr. servaddr.h> #include<sys/types. printf("\nReceived Messages\n").(struct sockaddr*)&servaddr. sd2=bind(sd. do { recv(nsd. printf("\n_____________________\n"). clilen=sizeof(cliaddr).20.h> #include<string.(struct sockaddr*)&cliaddr.h> #include<netinet/in.

else printf("Connected\n"). struct sockaddr_in servaddr. } CLIENT #include<stdio.send(nsd.revmsg[20].SOCK_STREAM.s_addr=htonl(INADDR_ANY).20.20. servaddr.0)."bye")!=0). do { fgets(sendmsg.revmsg. printf("%s". servaddr.sin_family=AF_INET. char sendmsg[20]. recv(csd.sendmsg.h> #include<sys/types. printf("Enter the port\n").cport.stdin)."bye")!=0). scanf("%d".revmsg). } while(strcmp(revmsg. wait(20).len.20. send(csd. sendmsg[len-1]='\0'. if(csd<0) printf("Can't Create\n"). servaddr.sendmsg. wait(20).sizeof(servaddr))<0) printf("Can't Connect\n").20. else printf("Scocket is Created\n").(struct sockaddr*)&servaddr.sin_port=htons(cport). len=strlen(sendmsg).h> #include<netinet/in.0).0). } while(strcmp(sendmsg. if(connect(csd.h> main() { int csd.0).sin_addr.&cport). csd=socket(AF_INET. } .

/a.c.out Enter the server port… 6543 Socket is Created Binded Accepted Received Messages…. Hello RESULT Thus the C program for chat using TCP is executed and the output is verified successfully .out Enter the port 6523 Socket is Created… Connected…… Hello Server Side [1me16@localhost ~]$ cc tcpserver. /a.c [1me16@localhost ~]$.c [1me16@localhost ~]$.OUTPUT: Client Side [1me16@localhost ~]$ cc tcpclient.

Step 4: Name the socket using bind( ) system call. CLIENT Step 1: Start the program. Step 6: Stop the program execution. Step 2: Create an unnamed socket for client using socket Step 3: Call with parameters AF_INET as domain an SOCK_DGRAM as type. Step 5: The Sendto( ) system call is used to deliver the Message to the server. Step 3: Name the socket using bind( ) system call with the parameters server_sockfd and the server address(sin_addr and sin_sport). Step 2: Create an unnamed socket for the server using the parameters AF_INET as domain and the SOCK_DGRAM as type.Ex. Step 5: Prints the message. Step 6: Stop the program execution. Step 4: The server gets the message from the client. .no:2 Date: AIM CLIENT-SERVER CHAT USING UDP To write a C program for implementing chat program using UDP. ALGORITHM SERVER Step 1: Start the program.

rbuff).0).sin_family=PF_INET. close(id).&len)<0) printf("Received Error\n"). len=sizeof(cadd).sizeof(rbuff).a. if(b<0) printf("Can't Bind"). int id.CLIENT SERVER CHAT USING UDP SERVER #include<stdio. scanf("%d". sadd.h> main() { struct sockaddr_in sadd. b=bind(id. else printf("Created\n"). printf("Enter the port Address\n").len.b. char rbuff[100]. else printf("Binded\n"). printf("____________________\n").cadd. sadd. sadd.sin_port=htons(port).(struct sockaddr*)&sadd.s_addr=htonl(INADDR_ANY).h> #include<sys/types.sin_addr.0.port.h> #include<sys/socket.SOCK_DGRAM. else printf("Server received =%s\n".(struct sockaddr*)&cadd. printf("~~~~~~\n"). if(recvfrom(id. id=socket(PF_INET.rbuff.h> #include<netinet/in. if(id<0) printf("Can't Create\n").sizeof(sadd)). } .&port).

scanf("%s". scanf("%d".SOCK_DGRAM.serstr).s_addr=inet_addr(serstr).s.sizeof(str).(struct sockaddr*)&cadd. close(id). int id. if(id<0) printf("Can't Create\n").sin_family=PF_INET.&port).0).h> #include<netinet/in.n. } . printf("Enter the port Address\n").cadd. id=socket(PF_INET.h> #include<sys/types.len.sizeof(cadd))<0) printf("Transmit Error").port.b. else printf("Socket is Created\n"). if(sendto(id.sin_addr. cadd. printf("Enter the IP address\n").sin_port=htons(port).str).h> #include<sys/socket.CLIENT #include<stdio. printf("Enter the Data\n").str). char str[100].0. cadd.(struct sockaddr*)&cadd. b=bind(id.str. cadd.c.serstr[100].sizeof(cadd)). else printf("Server Transmitted=%s\n".h> main() { struct sockaddr_in sadd. scanf("%s".

out Socket is Created… Enter the IP Address 172.c [1me16@localhost ~]$. RESULT Thus the C program for chat using UDP is executed and the output is verified successfully. /a. /a. .out Created Enter the port address ………….15.c [1me16@localhost ~]$.170. 6543 Binded …………….OUTPUT: Client Side [1me16@localhost ~]$ cc udpclient.104 Enter the port address 6543 Enter the data Hello Server transmitted = hello Server Side [1me16@localhost ~]$ cc udpserver.

Step 9: Stop the process. Step 7: Print the IP address sent by the client to the server. Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type. Step 8: Else send the IP address to the server. Step 8: Stop the program execution. Step 5: Now connect the socket to server using connect( ) system call. Step 2: Create an unnamed socket for client using socket( ) system. Step 5: Accept the connection using accept( ) system call when client requests for connection. Step 7: If there is no connection.Ex. Step 2: Create an unnamed socket for the server using the parameters AF_INET as domain and the SOCK_STREAM as type. Step 4: Name the socket using bind( ) system call.then the connection is not established and the stop the process. Step 6: If the descriptor is less than zero. ALGORITHM SERVER Step 1: Start the program. Step 6: If the descriptor is less than zero. Step 4: Create a connection queue and wait for clients using the listen( ) system call with the number of clients request as parameters. . 3a Date: AIM PRINTING THE CLIENT ADDRESS AT THE SERVER END To write a C program for printing the client address at the server end. No. CLIENT Step 1: Start the program.then terminate the process. then the connection is not established. Step 3: Name the socket using bind( ) system call with the parameters server_sockfd and the server address(sin_addr and sin_sport).

sd2=bind(sd.SOCK_STREAM. printf("The Client Address is %s". else printf("Socket is Created\n").len.h> #include<string.h> #include<sys/types.h> main() { int sd.(struct sockaddr*)&servaddr.nsd. } . nsd=accept(sd.sin_addr.5).clilen.s_addr=inet_addr("172. sd=socket(AF_INET. struct sockaddr_in servaddr.rcvmsg[20].cliaddr.sport.sizeof(servaddr)).&sport). servaddr.sin_port=htons(sport). printf("Enter the Port\n").h> #include<sys/socket.(struct sockaddr*)&cliaddr.&clilen). else printf("\n Binded\n").h> #include<netinet/in.170. servaddr. else printf("Accepted\n").PRINTING THE CLIENT ADDRESS AT THE SERVER END SERVER #include<stdio. listen(sd.inet_ntoa(cliaddr.sin_family=AF_INET.sd2.15. if(sd<0) printf("Can't Create \n"). char sendmsg[20]. if(nsd<0) printf("Can't Accept\n").0). servaddr.104"). scanf("%d".s_addr)).sin_addr. clilen=sizeof(cliaddr). if(sd2<0) printf(" Can't Bind\n").

len.sizeof(servaddr))<0) printf("Can't Connect\n"). csd=socket(AF_INET.s_addr=inet_addr("172.sin_addr.(struct sockaddr*)&servaddr.cport. else printf("Connected\n"). servaddr. printf("Enter the port\n").170.revmsg[20].104").CLIENT #include<stdio. char sendmsg[20].sin_port=htons(cport).h> #include<sys/types. servaddr. struct sockaddr_in servaddr. } .h> #include<netinet/in. scanf("%d".sin_family=AF_INET.SOCK_STREAM.h> main() { int csd. else printf("Scocket is Created\n").15. if(csd<0) printf("Can't Create\n"). if(connect(csd.0).&cport). servaddr.

.c [1me16@localhost ~]$..c [1me16@localhost ~]$.out Enter the port: 6543 Created.OUTPUT: Client Side [1me16@localhost ~]$ cc addressclient. /a. /a. Binded…… RESULT Thus the C program for printing the client IP Address at the server end is executed and the output is verified successfully... Server Side [1me16@localhost ~]$ cc addressserver..out Enter the port: 6543 Socket is Created.

Step 7 :Accept the connection using accept( ) system call when the client request for connection. Step 4 :Now connect the socket to server using connect( ) system call. Step 6 :Create a connection queue and wait for clients using listen() system call with The number of clients requests as parameter. ALGORITHM SERVER Step 1 :Start the program Step 2 :Create an unnamed socket for the server using parameters AF_INET as domain and SOCK_STREAM as type. Step 4 :Get the server port number. Step 5 :The recv() system call gets the response of Date-Time request from the server. Step 3 : Declare the time variables t. . Step 2 :Create an unnamed socket for the client using parameters AF_INET as domain and SOCK_STREAM as type. Step 8 :Stop the Program execution. CLIENT Step 1 :Start the program. Step 6 :Print the date and time Step 7 :Stop the program. Step 3 :Get the client port number.Ex.no: 3b Date: AIM DATE-TIME SERVER To write a C program for implementing the simple TCP client-server where the server acts as a Date-Time server. Step 5 :Register the host address to the system by using bind() system call in server side.

(struct sockaddr*)&cliaddr. } . scanf("%d".0). time(&t). char sendmsg[20].sin_port=htons(sport). servaddr.sendmsg). sd2=bind(sd.(struct sockaddr*)&servaddr.sizeof(servaddr)). send(nsd.sport.h> #include<sys/types.h> main() { int sd.DISPLAYING TIME AT THE CLIENT END SERVER #include<stdio.h> #include<netinet/in.h> #include<string.rcvmsg[20].h> #include<time.&clilen). sd=socket(AF_INET.&sport).100.clilen. nsd=accept(sd.sin_family=AF_INET. servaddr. servaddr.cliaddr. clilen=sizeof(cliaddr). if(nsd<0) printf("Can't Accept\n"). else printf("Accepted\n").sd2.len.5). printf("Enter the Port no\n"). printf("%s". listen(sd. struct sockaddr_in servaddr.sin_addr. if(sd2<0) printf(" Can't Bind\n").0).SOCK_STREAM. else printf("Socket is Created\n"). time_t t.sendmsg.ctime(&t)).s_addr=htonl(INADDR_ANY). else printf("\n Binded \n"). strcpy(sendmsg. if(sd<0) printf("Can't Create \n").nsd.

} . if(connect(csd. struct sockaddr_in servaddr.h> #include<netinet/in.revmsg. scanf("%d".0).h> #include<stdlib.cport.sin_family=AF_INET.h> main() { int csd.sizeof(servaddr))<0) printf("Connection error\n"). if(csd<0) printf("Can't Create\n"). recv(csd. servaddr. else printf("Socket is Created\n"). csd=socket(AF_INET.CLIENT #include<stdio. printf("%s\n".s_addr=htonl(INADDR_ANY).len.&cport). printf("Enter the port\n").h> #include<sys/types.h> #include<time.h> #include<sys/socket.revmsg). servaddr.sin_addr. servaddr. char revmsg[100].sin_port=htons(cport).SOCK_STREAM.100.0).(struct sockaddr*)&servaddr.

..out Enter the port: 8543 Fri Sep 17 03:05:27 2010 Socket is Created.c [1me16@localhost ~]$.. /a.out Enter the port: 8543 Socket is Created.c [1me16@localhost ~]$. Connected… Server Side [1me16@localhost ~]$ cc dateserver.OUTPUT: Client Side [1me16@localhost ~]$ cc dateclient. /a. RESULT Thus the C program for printing Date and time is executed and the output is verified successfully.. .

Step 6:Create a Child process using fork( ) system call. Step 8:If pid is not equal to zero then exit the process. Step 3:Get the client port number. CLIENT: Step 1:Start the program. Step 6:The file is transferred from client to server using send ( ) function. Step 4:Register the host address to the system by using bind() system call in server side. Step 4:Now connect the socket to server using connect( ) system call. . Step 9:Stop the Program execution. Step 5:Create a connection queue and wait for clients using listen() system call with the number of clients requests as parameter.no:3c Date: AIM: FILE TRANSFER USING TCP To write a C program for transferring a file using TCP. ALGORITHM: SERVER: Step 1:Start the program. Step 7:If the process identification number is equal to zero accept the connection using accept( ) system call when the client request for connection. Step 2:Create an unnamed socket for the client using parameters AF_INET as domain and SOCK_STREAM as type. Step 5:Enter the file name.Ex. Step 7:Print the contents of the file in a new file. Step 8:Stop the program. Step 2:Create an unnamed socket for the server using parameters AF_INET as domain and SOCK_STREAM as type. Step 3:Get the server port number.

a. newsd=accept(sd.h> #include<string. servaddr.fileread[100].pid.cliaddr. servaddr.sin_family=AF_INET. else printf("Socket is Created\n").(struct sockaddr*)&servaddr.FILE TRANSFER PROTOCOL USING TCP SERVER #include<stdio. a=sizeof(servaddr).clilen. if(sd<0) printf("Can't Create \n").bd. servaddr. fp=fopen(rcv. else printf("\n Binded\n").(struct sockaddr*)&cliaddr.SOCK_STREAM.&clilen).file[100]. clilen=sizeof(cliaddr).100.n.cli. char name[100].ser.sin_port=htons(port).rcv.ch. else printf("Accepted\n").newsd. scanf("%d".5). n=recv(newsd. bd=bind(sd. if(fp==NULL) { .s_addr=htonl(INADDR_ANY). struct sockaddr_in servaddr.sin_addr.h> main() { FILE *fp.&port).rcv[100]. if(bd<0) printf(" Can't Bind\n")."r").fname[100]. listen(sd.h> #include<sys/types.0).port.a). if(newsd<0) printf("Can't Accept\n"). rcv[n]='\0'. sd=socket(AF_INET. printf("Enter the port address: ").0). int sd.h> #include<netinet/in.

0)."error".\n").ser. } } CLIENT #include<stdio.."completed". } if(!fgets(fileread..n.sizeof(fileread).5..fp)) { send(newsd. scanf("%d".h> main() { FILE *fp.fname[100]. } else printf("Socket is Created.fileread.0). char name[100]. } return(0).cli. .fp)) { if(send(newsd.. close(newsd).SOCK_STREAM.h> #include<sys/socket.sizeof(fileread).999999999. int csd.cport. csd=socket(AF_INET."). } else { while(fgets(fileread.&cport). exit(0).0).rcvmsg[100].rcvg[100].send(newsd.0)<0) { printf("Can't send\n"). struct sockaddr_in servaddr. if(csd<0) { printf("Error.sizeof(fileread).h> #include<netinet/in. printf("Enter the port").newsd.s. } sleep(1).

sin_family=AF_INET. break.100. } } ..name. rcvg[s]='\0'. fprintf(fp. printf("Enter the existing file name: "). close(csd). printf("\nEnter the new filename: "). send(csd.. servaddr.rcvg.... while(1) { s=recv(csd. fp=fopen(fname.rcvg). scanf("%s".sin_addr.\n"). if(connect(csd.\n").\n").0).name)."error")==0) printf("File is not Available.servaddr.(struct sockaddr*)&servaddr. fclose(fp)..."completed")==0) { printf("file is transferred.sizeof(servaddr))<0) printf("Error in Connection."w").\n"). scanf("%s". } else fputs(rcvg. else printf("Connected.sin_port=htons(cport).fname)..sizeof(name). if(strcmp(rcvg.0). if(strcmp(rcvg."%s".servaddr.stdout).s_addr=htonl(INADDR_ANY).

OUTPUT: Server Side [1me16@localhost ~]$ cc ftpclient. /a. . /a...c [1me16@localhost ~]$.out Socket is Created.. RESULT Thus the C program for transferring file from one machine to another machine using TCP is executed and the output is verified successfully. Connected Enter the existing file name: net Enter the new file name: network Welcome to Network Lab File is transferred.c [1me16@localhost ~]$.out Enter the port address: 8663 Socket is Created Binded Connected… Client Side [1me16@localhost ~]$ cc ftpserver.

then send the acknowledgement of the last frame. . Step 6: Stop the program execution. Step 3: Set the size of the window. which was successfully received. Step 5: Keep on receiving and acknowledging the frames until the sender sends. Step 4: Send the frames upto the size of the window to the receiver Step 5: If any of the frames are lost then retransmit those frames to the receiver Step 6: Stop the execution. Step 4: If any of the frames is lost. send the acknowledgement for the last frame to the sender. RECEIVER Step 1: Start the program.EX.NO:4 DATE: AIM SIMULATION OF SLIDING WINDOW PROTOCOL To write a C program for the simulation of Sliding Window Protocol. ALGORITHM SENDER Step 1: Start the program. Step 3: If all the frames are successfully received. Step 2: Create a Socket for the Sender and bind it with the receiver. bind it and listen for the frames from the sender. Step 2: Create the Socket for the Receiver.

sin_family=AF_INET.0). else printf("Socket is Created\n").0).port.(struct sockaddr*)&cliaddr. scanf("%s". clilen=sizeof(cliaddr).sendmsg[20].5).sin_port=htons(port).sin_addr. a=sizeof(servaddr). printf("Enter the lost frame\n").s_addr=htonl(INADDR_ANY).SOCK_STREAM. scanf("%d".h> #include<string.20. else printf("\n Binded\n").(struct sockaddr*)&servaddr.recvmsg). if(sd<0) printf("Can't Create \n").h> main() { int a. bd=bind(sd. servaddr.h> #include<sys/socket.20.&port). newsd=accept(sd. struct sockaddr_in servaddr.bd.cliaddr. send(newsd. if(newsd<0) printf("Can't Accept\n").lost). servaddr.lost.recvmsg[20]. sd=socket(AF_INET. } . if(bd<0) printf(" Can't Bind\n").newsd.clilen.&clilen). char lost[20]. listen(sd.recvmsg.h> #include<sys/types. printf("Enter the port no\n"). recv(newsd.sd.0).a). servaddr.SLIDING WINDOW PROTOCOL SERVER #include<stdio.h> #include<netinet/in. else printf("Accepted\n"). printf("\n Frame %s is successfully received".

servaddr. scanf("%d".&n).0). else printf("Socket is Created\n").CLIENT #include<stdio. if(sd<0) printf("Can't Create\n").h> #include<sys/types.(struct sockaddr*)&servaddr.sin_family=AF_INET.s_addr=htonl(INADDR_ANY). struct sockaddr_in servaddr.i<=n.0).&port). char sendmsg[100]. } . strcpy(sendmsg.sd.h> #include<string.port. servaddr.0).recvmsg).recvmsg). if(connect(sd.sizeof(servaddr))<0) printf("Can't Connect\n").h> main() { int i.SOCK_STREAM.i++) printf("Frame %d\n". printf("Enter the port\n"). printf("\n Lost frame %s is retransmitted ". else printf("Connected\n").sendmsg. servaddr.20.sin_port=htons(port). for(i=1.h> #include<netinet/in. recv(sd. printf("\nThe frames all\n").n. send(sd.i). sd=socket(AF_INET.sin_addr.20. scanf("%d". printf("Enter the no of frames\n").recvmsg.recvmsg[100].

OUTPUT: Server: [1me16alhost~]: VI swserver..c [1me16alhost~]: /a.c [1me16alhost~]: /a.c [1me16alhost~]: CC swserver.c [1me16alhost~]: CC swclient.c is successfully transmitted Client: [1me16alhost~]: VI swclient. .out Enter the client port no 8543 Socket is created Connected………….out Enter the port address 8543 Socket is created Binded Accepted Enter the lost frame: 3 Frame tcpserver. Enter the no of frames: 4 The frames all Frame 1/n Frame 2/n Frame 3/n Frame 4/n RESULT Thus the C program for the simulation of Sliding Window Protocol has been executed and the output is verified successfully.

Step 4: Send the hostname to the server to be resolved. Step 2: Create the Socket for the Server. Step 8: If domain matches then send the corresponding address to the client. Step 5: If the server responds the print the address and terminates the process.EX. Step 9: Stop the program execution. Step 3: Bind the Socket to the Port. CLIENT Step 1: Start the program. Step 2: Create the Socket for the client. Step 3: Connect the Socket to the server. . Step 6: Get the domain name from the client. Step 5: Receive the IP address from the client to be resolved. Step 4: Listen for the incoming client connection.NO:5 DATE: AIM DOMAIN NAME SYSTEM To write a C program for the simulation of Domain Name System ALGORITHM SERVER Step 1: Start the program. Step 7: Check the existence of the domain in the server.

15.recvmsg[20]. sd=socket(AF_INET.i++) { if(strcmp(recvmsg. servaddr.len.yahoo. recv(nsd. servaddr.clilen.33.sin_port=htons(sport)."172.sd2.15. char ipid[20][20]={"172."172.sport.20. if(nsd<0) printf("Can't Accept\n").h> #include<sys/types. printf("DNS Server Side\n").h> #include<string."www. char hostid[20][20]={"www. nsd=accept(sd. else printf("\n Binded\n"). for(i=0.5).66".&sport). scanf("%d". break.(struct sockaddr*)&cliaddr.15. else printf("Socket is Created\n").20.sizeof(servaddr)).com".0).55". if(sd<0) printf("Can't Create \n").hotmail."www.DOMAIN NAME SYSTEM SERVER #include<stdio. char sendmsg[20]. if(sd2<0) printf("Can't Bind\n").20).(struct sockaddr*)&servaddr.64.15.com". listen(sd. }}} .hostid[i])==0) { send(nsd. else printf("Accepted\n").sin_family=AF_INET.&clilen).s_addr=htonl(INADDR_ANY). servaddr.recvmsg.nsd.ipid[i]. struct sockaddr_in servaddr.44.0).i.h> main() { int sd."172. clilen=sizeof(cliaddr).22.33"}.SOCK_STREAM. printf("Enter the Port\n"). sd2=bind(sd.sin_addr.com"}.44".h> #include<netinet/in.cliaddr.i<4.google.

len. else printf("Socket is Created\n").20.s_addr=htonl(INADDR_ANY).20).sin_addr. csd=socket(AF_INET.h> main() { int csd. recv(csd. } .20. struct sockaddr_in servaddr. printf("The Coresponding IP Address is\n").h> #include<netinet/in. printf("%s". else printf("Connected\n").sin_family=AF_INET. send(csd. char sendmsg[20]. servaddr. scanf("%s".cport.h> #include<sys/types.sin_port=htons(cport). printf("DNS Client Side\n"). servaddr.recvmsg.0). servaddr. if(csd<0) printf("Can't Create\n").SOCK_STREAM.sizeof(servaddr))<0) printf("Can't Connect\n").recvmsg).CLIENT #include<stdio. if(connect(csd.sendmsg).(struct sockaddr*)&servaddr.0). scanf("%d". printf("Enter the host address\n").&cport).sendmsg. printf("Enter the Client port\n").recvmsg[20].

c [1me16alhost~]: /a.yahoo. Enter the host address www.64..out Enter the port no 8543 Socket is created Binded Accepted Client: [1me16alhost~]: VI dnsclient.com The corresponding IP Address is 172.OUTPUT: Server: [1me16alhost~]: VI dnsserver.c [1me16alhost~]: CC dnsclient.c [1me16alhost~]: /a. .66 RESULT Thus the C program for the simulation of Domain Name System has been executed and the output is verified successfully.out Enter the client port no 8543 Socket is created Connected………….15.c [1me16alhost~]: CC dnsserver.

Step 8: Update distance and previous lists based on those vertices which can be immediately reached from the current vertex. Step 4: All values in visited list are set to false. Step 6: Current node is set as the starting vertex.EX. Step 10: Repeat (from step 6) until all nodes are visited. and a current vertex. a visited list. Step 3: All the values in the distance list are set to infinity except the starting vertex which is set to zero. Step 5: All values in the previous list are set to a special value signifying that they are undefined. .NO:6 DATE: AIM SIMULATION OF ROUTING PROTOCOLS To Simulate Shortest Path Routing Algorithm ALGORITHM Step 1: Start the Program Step 2: Create a distance list. Step 9: Update the current vertex to the unvisited vertex that can be reached by the shortest path from the starting vertex. a previous vertex list. Step 11: Stop the program execution. Step 7: Mark the current vertex as visited.

mark[15]. } } cout<<"Enter the source Vector: ".i++) { mark[i]=0. }. pathestimate[i]=999.no. predessor[i]=0. void printpath(int). void read().i++) { cout<<"Enter the weight for row: "<<i. void output(). } pathestimate[source]=0. cin>>no.SIMULATION OF OSPF ROUTING PROTOCOL #include<iostream. void initialize(). int set[15].predessor[15].i<=no. } void dij::initialize() { for(int i=1.h> class dij { private: int graph[15][15]. for(int j=1.pathestimate[15].source.j++) { cin>>graph[i][j].h> #include<conio.i<=no. void algorithm(). cin>>source. . public: int minimum(). for(int i=1. void dij::read() { cout<<"Enter the no of vertices: ". cout<<"Enter the Adjacent matrices".j<=no.

} } void dij::output() { .. set[++count]=u. mark[u]=1.u. } else if(predessor[i]==0) cout<<"No path from"<<source<<"to"<<i.. else { printpath(predessor[i]). while(count<no) { u=minimum()."<<i.i++) { if(graph[u][i]>0) { if(mark[i]!=1) { if(pathestimate[i]>pathestimate[u]+graph[u][i]) { predessor[i]=u. for(int i=1. if(i==source) { cout<<source. int count=0..} void dij::algorithm() { initialize().. pathestimate[i]=pathestimate[u]+graph[u][i].i. } } } } //for loop } //while loop } void dij::printpath(int i) { cout<<endl. cout<<".i<=no.

getch(). if(pathestimate[i]!=999) cout<<"->("<<pathestimate[i]<<")\n". d. for(i=1. t=i.i++) { if(mark[i]!=1) { if(min>=pathestimate[i]) { min = pathestimate[i]. } int dij::minimum() { int min=999. } cout<<endl. } . d. dij d. } void main() { clrscr().t. } } } return t.algorithm(). d.for(int i=1.read().i.i++) { printpath(i).output().i<=no.i<=no.

. 3 -> (1) RESULT: Thus the Program for simulating Shortest Path Routing Algorithm is executed and the output is verified successfully. 2.> (1) 1…… 2 …….OUTPUT Enter the no of vertices: 3 Enter the Adjacent matrices Enter the weight for row: 1 0 1 3 Enter the weight for row: 2 2 1 1 Enter the weight for row: 3 2 1 1 Enter the source vector: 1 1 -> (0) 1…….

Step 2: Create an object for the URL class. modified date etc. using appropriate the methods.EX.NO:6b DATE: AIM UNIFORM RESOURCE LOCATOR (URL) To retrieve the data using Uniform Resource Locators ALGORITHM Step 1: Start the Program. Step 3: Specify the address from which the data is to be retrieved inside the URL class Step 4: Open the URL connection Step 5: Request the content Length. Step 6: Display the contents to the user Step 7: Stop the program .

t. printf("\n Date : %d-%d-%d Time : %d:%d:%d \n".d.h> #include<stdio.da_mon. getch().h> #include<dos. printf("Content type = text/html\n"). len++. clrscr().len).h> #include<string. cout<<c. len++. struct time t.t.h> #include<conio.da_day. int len=0.ti_min.UNIFORM RESOURCE LOCATOR #include<iostream. getdate(&d).ti_hour. cout<<c.da_year.ti_sec). FILE *fp. fp=fopen("welcome.d. } printf("\n Content length is %d".t.html". } . c=fgetc(fp)."r"). gettime(&t). while((c=fgetc(fp))!=-1) { if(c!='\n'||' '). struct date d.d.h> void main() { char c.

OUTPUT: CONTENT TYPE=text/html Date:03-11-2010 time:15:13:28 <html> <head> <title>welcome</title> <body bgcolor=”blue”> <h1>welcome to network lab-1</h> </body> </html> content length is 109 RESULT Thus the program for retrieving the data using URL is executed and the output is verified successfully. .

Step 5: Now connect the socket to server using connect ( ) system call. Step 6: Accept the connection using accept ( ) system call when client requests for connection. CLIENT: Step 1: Start the program. . Step 3: Name the socket using bind ( ) system call with the parameters server_sockfd and the server address (sin_addr and sin_sport). Step 4: Create a connection queue and wait for clients using the listen( ) system call with the number of clients request as parameters. Step 2: Create an unnamed socket for the server using the parameters AF_INET as domain and the SOCK_STREAM as type.Ex. Step 10: If the message is equal to „Bye‟then print good bye message and terminate the process. Step 11: Stop the process. Step 7: If the message is not equal to „Bye‟ then print the message to the server output device and repeat the steps 6 & 7. Step 7: Get the message which has to be sent to the client and check that it is not equal to „Bye‟. Step 9: If the message is „Bye‟ then terminates the connection with current client and Go to step 5. Step 5: Get the client‟s id as input from the user to communicate.No:8 Date: AIM: MULTICLIENT-SERVER CHAT To write a C program for implementing Client-Server Chat using TCP. Step 6: Read the message from the server socket and compare it with „Bye‟. Step 2: Create an unnamed socket for client using socket ( ) system. Step 9: Write the message to server sockfd and goto step 4. Step 8: If the message is not equal to „Bye‟ then write the message to the client and Goto step 6. Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type. If the client‟s id is 0 then go to step 10 otherwise go to step 6. Step 8: Get the message from the client side. ALGORITHM: SERVER: Step 1: Start the program. Step 4: Name the socket using bind( ) system call. Step 10: Stop the program execution.

len.s_addr=htonl(INADDR_ANY).rcvmsg[20]. else printf("Accepted\n"). if(sd<0) printf("Can't Create \n").5). if(i==0) exit(0). printf("Client %d is connected\n". scanf("%d".h> #include<netinet/in.&i). sd2=bind(sd. else printf("Socket is Created\n"). printf(“Enter the port no:\n”). sd=socket(AF_INET. servaddr.&clilen).h> #include<sys/types.clilen. listen(sd.&sport).cliaddr.h> main() { int i. do . else printf("\n Binded\n"). servaddr.sd. do { printf("Enter the client no to communicate\n").sizeof(servaddr)).(struct sockaddr*)&servaddr. nsd=accept(sd.sin_family=AF_INET.i).0).sport.SOCK_STREAM. scanf("%d". if(sd2<0) printf("Can't Bind\n").sd2. servaddr.h> #include<string. char sendmsg[20]. if(nsd<0) printf("Can't Accept\n").nsd. struct sockaddr_in servaddr.MULTI USER CHAT SERVER #include<stdio.(struct sockaddr*)&cliaddr. clilen=sizeof(cliaddr).sin_port=htons(sport).sin_addr.

cport. servaddr.rcvmsg. } CLIENT . else printf("Socket is Created\n").20.0).0). struct sockaddr_in servaddr. if(csd<0) printf("Can't Create\n"). servaddr.sizeof(servaddr))<0) printf("Can't Connect\n").h> #include<netinet/in. sendmsg[len-1]='\0'. do { fgets(sendmsg.20. else printf("Connected\n").{ recv(nsd.sendmsg.sendmsg.sin_port=htons(cport).s_addr=htonl(INADDR_ANY). if(connect(csd. wait(20). send(nsd.20. len=strlen(sendmsg). printf("Enter the port no:\n"). fgets(sendmsg. printf("%s". }while(strcmp(sendmsg.(struct sockaddr*)&servaddr. servaddr.SOCK_STREAM.sin_family=AF_INET. .stdin).revmsg[20].stdin).h> main() { int csd. }while(i!=0).h> #include<sys/types. sendmsg[len-1]='\0'. char sendmsg[20].len.0). scanf("%d".sin_addr.&cport).20.0).20. csd=socket(AF_INET. len=strlen(sendmsg). send(csd.rcvmsg). wait(20).1 #include<stdio."bye")!=0).

&cport).sizeof(servaddr))<0) printf("Can't Connect\n").revmsg. if(csd<0) printf("Can't Create\n"). csd=socket(AF_INET.h> #include<sys/types.sendmsg."bye")!=0).0).0). else printf("Socket is Created\n"). char sendmsg[20]. sendmsg[len-1]='\0'.s_addr=htonl(INADDR_ANY).h> #include<netinet/in. servaddr.sin_port=htons(cport).revmsg.revmsg). } while(strcmp(revmsg.0).recv(csd. scanf("%d". servaddr. else printf("Connected\n").20. if(connect(csd. printf("%s".0).stdin). len=strlen(sendmsg). send(csd. printf("Enter the port no:\n").sin_family=AF_INET. wait(20). recv(csd.(struct sockaddr*)&servaddr. } . } CLIENT . do { fgets(sendmsg.len.2 #include<stdio.SOCK_STREAM.sin_addr.cport. struct sockaddr_in servaddr.revmsg)."bye")!=0). servaddr. printf("%s".20.20.revmsg[20].20. } while(strcmp(revmsg.h> main() { int csd.

c [1me2@localhost ~]$ cc multiuserclient1.c [1me2@localhost ~]$ cc Multiuserserverc [1me2@localhost ~]$ .out Enter the port no 8543 Socket is created Connected hiiiiii Byeeeee ./a.OUTPUT: SERVER SIDE: [1me2@localhost ~]$ vi Multiuserserver.c [1me2@localhost ~]$ ./a.out Enter the port no 8543 socket is created Binded Enter the client to communicate: 1 Client 1 is connected Accepted hiiiii Byeeeeee Enter the client no to communicate: 2 client 2 is connected Accepted hiiiiiiiiii hello Enter the client no to communicate: 0 CLIENT SIDE 1: [1me2@localhost ~]$ vi multiuserclient1.

c [1me2@localhost ~]$ cc multiuserclient2.CLIENT SIDE –2: [1me2@localhost ~]$ vi multiuserclient2. ./a.c [1me2@localhost ~]$ .out Enter the port no 8543 Socket is created Connected Hiiiiiiiii hello RESULT Thus the C program for chat multiclient-serve chat program using tcp has been executed successfully.

Step 10: Receive the message. Step 9: Read the input for the object. print and terminate the process. . Step 2: Create an unnamed socket for the server using the parameters AF_INET as domain and the SOCK_STREAM as type. Step 3: Call with parameters AF_INET as domain and SOCK_STREAM as type. send it and receive the details of the TCP connection of that object from the agent. Step 4: Name the socket using bind ( ) system call. Step 5: Accept the connection using accept( ) system call when manager requests for connection. If the request is for „TCP connections‟ then send the details of the requested object. No:9 Date: AIM: SIMULATION OF SIMPLE NETWORK MANAGEMENT PROTOCOLS To write a C program for simulation of Simple Network management Protocols. AGENTS Step 1: Start the program. Step 11: Stop the process. Go to step 10. send it and receive the details of the system from the agent. else if the request is for „System‟ then send the details of the requested system. Step 6: Get the input for the type of information needed from the agent. Step 8: Read the input for the object.Ex. Step 7: Stop the program execution. Step 7: If the input is equal to „TCP connection‟ then goto next step else If it is equal to „system‟ Goto step 9. Step 3: Name the socket using bind( ) system call with the parameters server_sockfd and the manager address(sin_addr and sin_sport). ALGORITHM: MANAGER: Step 1: Start the program. Step 2: Create an unnamed socket for client using socket ( ) system. Step 5: Now connect the socket to agent using connect ( ) system call. Step 6: Receive the message from the manager. Step 4: Create a connection queue and wait for manager using the listen ( ) system call with the number of manager request as parameters. Go to step 10.

else printf("Socket is Created\n").recvmsg. else printf("\n Binded\n"). sd2=bind(sd. listen(sd.(struct sockaddr*)&servaddr.recvmsg[100]."client5"}. char oid[5][10]={"client1".0).nsd."3".0)."cleint4".clilen. servaddr. sd=socket(AF_INET.sin_family=AF_INET.h> #include<netinet/in."15".&clilen).sport. char wsize[5][5]={"5". for (i=0. if(nsd<0) printf("Can't Accept\n")."10".h> #include<string.SIMPLE NETWORK MANAGEMENT PROTOCOL AGENT1 #include<stdio.h> #include<sys/types.h> main() { int i. struct sockaddr_in servaddr. printf("\n_____________________\n").sin_port=htons(sport). clilen=sizeof(cliaddr). printf("\nEnter the Server port"). servaddr.s_addr=htonl(INADDR_ANY). else printf("Accepted\n").sizeof(servaddr)). if(sd<0) printf("Can't Create \n")."client2".100.i++) { .sd2.TCP Connection\n").&sport). if(sd2<0) printf(" Can't Bind\n"). servaddr."6"}.sd. printf("I'm the Agent .len.sin_addr."client3". recv(nsd.5). char sendmsg[20]. nsd=accept(sd.i<5.(struct sockaddr*)&cliaddr.SOCK_STREAM. scanf("%d".cliaddr.

100. struct sockaddr_in servaddr.sport.oid[i])==0) { send(nsd. break.30am"}.07". } } } AGENT 2 #include<stdio.if(strcmp(recvmsg. char mdate[5][15]={"1-10-095". char sendmsg[20]."System5"}. nsd=accept(sd. .0)."10pm".sd."System3".(struct sockaddr*)&servaddr.07.03.h> #include<netinet/in.(struct sockaddr*)&cliaddr.clilen."11am". scanf("%d".sin_addr. sd2=bind(sd. servaddr.&clilen).12. printf("\n_____________________\n"). servaddr.cliaddr."12.len. char oid[5][10]={"System1".wsize[i]. char time[5][15]={"9am". listen(sd.h> main() { int i."System4".&sport).sd2.30pm".recvmsg[100].nsd. if(sd2<0) printf(" Can't Bind\n"). sd=socket(AF_INET. clilen=sizeof(cliaddr)."14."17."System2".SOCK_STREAM. else printf("\n Binded\n").h> #include<sys/types. printf("Enter the Server port"). if(sd<0) printf("Can't Create \n").77"}."11.5).s_addr=htonl(INADDR_ANY)."11.0).sizeof(servaddr)).sin_port=htons(sport). servaddr.h> #include<string.sin_family=AF_INET.81". else printf("Socket is Created\n")."10-03-08".

oid[i])==0) { send(nsd.time[i].len. if(connect(csd.0).(struct sockaddr*)&servaddr.h> #include<netinet/in.sin_addr.rmsg[100].oid[100].i. for(i=0. } } } MANAGER #include<stdio. char sendmsg[20].mdate[i].h> main() { int csd. csd=socket(AF_INET. servaddr.i++) { if(strcmp(recvmsg. servaddr. printf("Enter the port\n").0). if(csd<0) printf("Can't Create\n").100.rcvmsg[100].100. recv(nsd. send(nsd.h> #include<sys/types.sin_port=htons(cport).SOCK_STREAM. scanf("%d". .recvmsg.if(nsd<0) printf("Can't Accept\n"). struct sockaddr_in servaddr. servaddr.i<5.&cport).0). else printf("Connected\n").sin_family=AF_INET.0).sizeof(servaddr))<0) printf("Can't Connect\n").cport.s_addr=htonl(INADDR_ANY). break.100. else printf("Accepted\n"). else printf("Scocket is Created\n").

oid. recv(csd.0). } } .\n").0). printf("\n 2. printf("\n The window size of %s is %s". printf("\nThe Manufacturing date for %s is %s".100. scanf("%d". recv(csd. scanf("%s".100.rmsg.100.rmsg. } else { printf("\nEnter the Object ID for the System\n").100.oid.0).rmsg). send(csd.100..oid.printf("\n 1. recv(csd. if(i==1) { printf("Enter the Object ID for Client\n")..oid).rmsg.oid. scanf("%s"..TCP Connection\n").rmsg). System \n"). send(csd. printf("Enter the number for the type of informtion needed.oid.0).&i).oid).0). printf("\nThe time of Last Utilization for %s is %s".rmsg).

c [1me14@localhost ~]$ cc Manger.TCP Connection 2.out Enter the Server port _____________________ 8543 Socket is Created Binded Accepted .c [1me14@localhost ~]$ . System Enter the number for the type of information needed: 1 Enter the Object ID for Client: Client1 The window size of client1 is 5 AGENT2: [1me14@localhost ~]$ vi Agent2./a.out I'm the Agent .TCP Connection Enter the Server port _____________________ 8543 Socket is created Binded Accepted MANGER: [1me14@localhost ~]$ vi Manager.c [1me14@localhost ~]$ ./a.c [1me14@localhost ~]$ .c [1me14@localhost ~]$ cc Agent2.c [1me14@localhost ~]$ cc Agent1./a.out Enter the port 8543 Socket is Created Connected 1.OUTPUT: AGENT1: [1me14@localhost ~]$ vi Agent1.

c [1me14@localhost ~]$ .03.MANGER: [1me14@localhost ~]$ vi Manager.out Enter the port 8543 Socket is Created Connected 1. System Enter the number for the type of informtion needed: 2 Enter the Object ID for Client: System3 The Manufacturing date for system3 is 14./a.c [1me14@localhost ~]$ cc Manger.81 The time of last utilization for system3 is 11am RESULT Thus the C program for simple network management protocols has been executed successfully. .TCP Connection 2.

*email_list[i]>0x0. exit(EXIT_FAILURE). int i=0.} #define LIST_LEN 4 //char *f="sam. tmp. char email_list[LIST_LEN][256]={{"mecse3@localhost. void email_it(char *filename).} #define cknltz(x) if((x)<0) {perror(""). main() { char fname[15].EMAIL #include <stdlib.txt".h> #include <string. printf("enter the filename\n"). "Please Review:". } } } . email_list[i])). if(system (fpBuffer)==(-1)) { perror("email failure").fname).localdomain"}."mail -s '%s %s' %s < %s". scanf("%s". cknltz(sprintf (fpBuffer. char fpBuffer[400]={0x0}.i++) { cknull(strcpy(tmp. filename. email_it(fname).h> #define cknull(x) if((x)==NULL) {perror("").filename)). exit(EXIT_FAILURE). for(i=0. exit(EXIT_FAILURE). } void email_it(char *filename) { char tmp[256]={0x0}.{0x0}}.

OUTPUT:
[1me2@localhost ~]$ vi email.c [1me2@localhost ~]$ cc email.c [1me2@localhost ~]$ ./a.out Enter the file name: sample.c [1me2@localhost ~]$/home/1me1/dead.letter….saved message in /home/1me1/dead.letter…..

RESULT
Thus the program for developing E-mail application is executed and the output is verified successfully.

STUDY OF NETWORK SIMULATOR PACKAGES
Ex. No: Date:
AIM:
To study about NS2 - Network Simulator

STUDY OF NS2

INTRODUCTION:
NS is a discrete event simulator targeted at networking research. NS provides substantial support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and satellite) networks. NS began as a variant of the REAL network simulator in 1989 and has evolved substantially over the past few years. In 1995 ns development was supported by DARPA through the VINT project at LBL, Xerox PARC, UCB, and USC/ISI. Currently ns development is support through DARPA with SAMAN and through NSF with CONSER, both in collaboration with other researchers including ACIRI. NS has always included substantial contributions from other researchers, including wireless code from the UCB Daedelus and CMU Monarch projects and Sun Microsystems. The network simulator ns-2 is a widely accepted discrete event network simulator, actively used for wired and wireless network simulations. It has a highly detailed model of the lower layers (Physical and MAC) of wireless IEEE 802.11 networks. Ns-2 has also an emulation feature, i.e. the ability to introduce the simulator into a live network and to simulate a desired network between real applications in real-time. Within the scope of this project we developed some methods and extensions to the ns-2 to combine wireless network simulation and network emulation.

OVERVIEW:
NS is an event driven network simulator developed at UC Berkeley that simulates variety of IP networks. It implements network protocols such as TCP and UDP, traffic source behavior such as FTP, Telnet, Web, CBR and VBR, router queue management mechanism such as Drop Tail, RED and CBQ, routing algorithms such as Dijkstra, and more. NS also implements multicasting and some of the MAC layer protocols for LAN simulations. The NS project is now a part of the VINT project that develops tools for simulation results display, analysis and converters that convert network topologies generated by well-known generators to NS formats. Currently, NS (version 2) written in C++ and OTcl (Tcl script language with Object-oriented extensions developed at MIT) is available. This document talks briefly about the basic structure of NS, and explains in detail how to use NS mostly by giving examples. Most of the figures that are used in describing the NS basic structure and network components are from the 5th VINT/NS Simulator Tutorial/Workshop slides and the NS Manual (formerly called "NS Notes and Documentation"), modified little bit as needed.

Figure 1. Simplified User's View of NS As shown in Figure 1, in a simplified user's view, NS is Object-oriented Tcl (OTcl) script interpreter that has a simulation event scheduler and network component object libraries, and network setup (plumbing) module libraries (actually, plumbing modules are implemented as member functions of the base simulator object). In other words, to use NS, you program in OTcl script language. To setup and run a simulation network, a user should write an OTcl script that initiates an event scheduler, sets up the network topology using the network objects and the plumbing functions in the library, and tells traffic sources when to start and stop transmitting packets through the event scheduler. The term "plumbing" is used for a network setup, because setting up a network is plumbing possible data paths among network objects by setting the "neighbor" pointer of an object to the address of an appropriate object. When a user wants to make a new network object, he or she can easily make an object either by writing a new object or by making a compound object from the object library, and plumb the data path through the object. This may sound like complicated job, but the plumbing OTcl modules actually make the job very easy. The power of NS comes from this plumbing. Another major component of NS beside network objects is the event scheduler. An event in NS is a packet ID that is unique for a packet with scheduled time and the pointer to an object that handles the event. In NS, an event scheduler keeps track of simulation time and fires all the events in the event queue scheduled for the current time by invoking appropriate network components, which usually are the ones who issued the events, and let them do the appropriate action associated with packet pointed by the event. Network components communicate with one another passing packets, however this does not consume actual simulation time. All the network components that need to spend some simulation time handling a packet (i.e. need a delay) use the event scheduler by issuing an event for the packet and waiting for the event to be fired to itself before doing further action handling the packet. For example, a network switch component that simulates a switch with 20 microseconds of switching delay issues an event for a packet to be switched to the scheduler as an event 20 microsecond later. The scheduler after 20 microseconds dequeues the event and fires it to the switch component, which then passes the packet to an appropriate output link component. Another use of an event scheduler is timer. NS is written not only in OTcl but in C++ also. For efficiency reason, NS separates the data path implementation from control path implementations. In order to

C++ and OTcl: The Duality Figure 3. The objects in C++ that do not need to be controlled in a simulation or internally used by another object do not need to be linked to OTcl. Likewise. In this way. Figure 2. an object (not in the data path) can be entirely implemented in OTcl. In this figure a general user (not an NS developer) can be thought of standing at the left bottom corner. These compiled objects are made available to the OTcl interpreter through an OTcl linkage that creates a matching OTcl object for each of the C++ objects and makes the control functions and the configurable variables specified by the C++ object act as member functions and member variables of the corresponding OTcl object. one might be wondering about how to obtain NS simulation results. there is a matching OTcl object hierarchy very similar to that of C++. the event scheduler and the basic network component objects in the data path are written and compiled using C++. Figure 2 shows an object hierarchy example in C++ and OTcl. The event schedulers and most of the network components are implemented in C++ and available to OTcl through an OTcl linkage that is implemented using tclcl. designing and running simulations in Tcl using the simulator objects in the OTcl library. . Architectural View of NS Figure 3 shows the general architecture of NS. At this point. One thing to note in the figure is that for C++ objects that have an OTcl linkage forming a hierarchy. This section briefly examined the general structure and architecture of NS.reduce packet and event processing time (not simulation time). It is also possible to add member functions and variables to a C++ linked OTcl object. The whole thing together makes NS. the controls of the C++ objects are given to OTcl. which is a OO extended Tcl interpreter with network simulator libraries.

when a simulation is finished. A tcp "sink" agent generates and sends ACK packets to the sender (tcp agent) and frees the received packets. and a connection is established to a tcp "sink" agent attached to n3. the maximum size of a packet that a "tcp" agent can generate is 1KByte.7 Mbps of bandwidth and 20 ms of delay. A "null" agent just frees the packets received.As shown in Figure 1. As default. if specified to do so in the input Tcl (or more specifically. A "udp" agent that is attached to n1 is connected to a "null" agent attached to n3. of which the maximum size is 10. The duplex link between n2 and n3 has 1. n1. The data can be used for simulation analysis (two simulation result analysis examples are presented in later sections) or as an input to a graphical simulation display tool called Network Animator (NAM) that is developed as a part of VINT project. n3) as shown in above figure. A "tcp" agent is attached to n0. NAM has a nice graphical user interface similar to that of a CD player (play. A Simple Network Topology and Simulation Scenario This network consists of 4 nodes (n0. although the graphical information cannot be used for accurate simulation analysis. Each node uses a DropTail queue. rewind. Figure 4. Example 3 is an OTcl script that creates the simple network configuration and runs the simulation scenario in Figure 4. and n1 and n2 have 2 Mbps of bandwidth and 10 ms of delay. A Simple NS Simulation Script . n2. Furthermore. fast forward. OTcl) script. This section shows a simple NS simulation script and explains what each line does. Example 3. pause and so on). NS produces one or more text-based output files that contain detailed simulation data. and also has a display speed controller. it can graphically present information such as throughput and number of packet drops at each link. The duplex links between n0 and n2.

therefore users should specify the queue-type when creating links. $ns color fid color: is to set color of the packets for a flow specified by the flow id (fid). $ns duplex-link node1 node2 bandwidth delay queue-type: creates two simplex links of specified bandwidth and delay. the output queue of a node is implemented as a part of a link. It also gives the file name that the trace will be written to later by the command $ns flush-trace. look at the files: "ns-2/tcl/libs/ns-lib.tcl". the member function trace-all is for recording the simulation trace in a general format. In the above simulation script. The "Simulator" object member function implementations are located in the "ns-2/tcl/lib/ns-lib. If the reader wants to use a RED queue.tcl" file. The NS implementation of a link is shown in a later section. In NS. simply replace the word DropTail with RED. and has no effect on the actual simulation. set ns [new Simulator]: generates an NS simulator object instance. Users can create a node by separately creating an address and a port classifier objects and connecting them together. attach-agent)  Set network component parameters (mostly for compound objects)  Create connections between agents (ex. DropTail queue is used. and users can create its subobjects and connect them and the nodes.The following is the explanation of the script above. Like a node.tcl" and "ns-2/tcl/libs/ns-node. post-simulation processes are specified. a link is a compound object. To see how a node is created. make connection between a "tcp" and "sink")  Specify NAM display options Most of member functions are for simulation setup and scheduling. In this function. Link source codes can be found in "ns- .0 "finish". In general. and connects the two specified nodes. an NS script starts with making a Simulator object instance. However. o Initialize the packet format (ignore this for now) o Create a scheduler (default is calendar scheduler) o Select the default address format (ignore this for now) The "Simulator" object has member functions that do the following:  Create compound objects such as nodes and links (described later)  Connect network component objects created (ex. $ns namtrace-all file-descriptor: This member function tells the simulator to record simulation traces in NAM input format. This member function of "Simulator" object is for the NAM display. and assigns it to variable ns (italics is used for variables and values in this section). set n0 [$ns node]: The member function node creates a node. A node in NS is compound object made of address and port classifiers (described in a later section). this member function of Simulator object makes the job easier. however some of them are for the NAM display. Similarly. proc finish {}: is called after this simulation is over by the command $ns at 5.

. $ns duplex-link-op node1 node2 . and attach them to nodes and agents respectively. users can comment these lines out and try the simulation. But in general. what this function does is call the attach member function of specified node. In NS. To see the effects of these lines. Refer to the NS documentation to find out how to do this. traffic sources such as FTP and CBR. Therefore. a user can do the same thing by. Therefore. a user should know the class names these objects (Agent/TCP. usually a . At this point. $ns queue-limit node1 node2 number: This line sets the queue limit of the two simplex links that connect node1 and node2 to the number specified. Assuming that all the network configuration is done.2/tcl/libs/ns-lib. To create agents or traffic sources.tcl" file..tcl" files. it works as a good indicator of what kind of network objects are available in NS and what are the configurable parameters.e. $ns attach-agent node agent: The attach-agent member function attaches an agent object created to a node object. For example. the next thing to do is write a simulation scenario (i. Please take a look at "ns2/tcl/libs/ns-lib. $ns at 0. This line establishes a network connection by setting the destination address to each others' network and port address pair.tcl" and "ns-2/tcl/libs/ns-link. the authors do not know how many of these kinds of member functions of Simulator objects are available and what they are. the next thing to do is to setup traffic agents such as TCP and UDP. which starts the CBR to transmit data. the next thing is to establish a logical network connection between them. set tcp [new Agent/TCP]: This line shows how to create a TCP agent. $n0 attach $tcp. mostly implemented in C++ and linked to OTcl. One thing to note is that you can insert error modules in a link component to simulate a lossy link (actually users can make and insert any network objects).tcl". Actually. The Simulator object has many scheduling member functions. But one shortcut is to look at the "ns-2/tcl/libs/ns-default. Agnet/TCPSink. Therefore. or NS documentation for more information. This file contains the default configurable parameter value settings for available network objects. the one that is mostly used is the following: $ns at time "string": This member function of a Simulator object makes the scheduler (scheduler_ is the variable that points the scheduler object created by [new Scheduler] command at the beginning of the script) to schedule the execution of the specified string at given simulation time. there are no specific Simulator object member functions that create these object instances.tcl" and "ns-2/tcl/libs/ns-link. which attaches the given agent to itself. simulation scheduling). for example. Now that the basic network setup is done. This information can be found in the NS documentation or partly in this documentation. Application/FTP and so on).: The next couple of lines are used for the NAM display.1 "$cbr start" will make the scheduler call a start member function of the CBR traffic source object. users can create any agent or traffic sources in this way. Agents and traffic sources are in fact basic objects (not compound objects). $ns connect agent1 agent2: After two agents that will communicate with each other are created. However.

traffic source does not transmit actual data. There are two types of nodes in NS. but it notifies the underlying agent that it has some amount of data to transmit. NETWORK COMPONENTS: Figure 6. A multicast node. A unicast node has an address classifier that does unicast routing and a port classifier. creates packets and sends them. NsObject class is the superclass of all basic network component objects that handle packets. The basic network components are further divided into two subclasses. As an ancestor class of TclObject. has . and the agent. just knowing how much of the data to transfer. After all network configuration. based on the number of the possible output data paths. This is done by $ns run. in addition. and switching objects that have possible multiple output data paths are under the Classifier class. network components. which may compose compound network objects such as nodes and links. Class Hierarchy (Partial) The root of the hierarchy is the TclObject class that is the superclass of all OTcl library objects (scheduler. timers and the other objects including NAM related ones). NODE AND ROUTING: A node is a compound object composed of a node entry object and classifiers as shown in Figure 7. the only thing left is to run the simulation. Connector and Classifier. The basic network objects that have only one output data path are under the Connector class. scheduling and post-simulation procedure specifications are done.

two simplex links in both directions are created as shown in Figure 8. To create Multicast nodes the user must explicitly notify in the input OTcl script.  Unicast . DV.$ns rtproto type . Unicast nodes are the default nodes. Figure 7. cost.a classifier that classify multicast packets from unicast packets and a multicast classifier that performs multicast routing. multi-path Multicast .$ns mrtproto type . the user can also select a specific routing protocol other than using a default one. After specifying the node type. . Session. right after creating a scheduler object.$ns multicast (right after set $ns [new Scheduler]) . ST. Node (Unicast and Multicast) In NS.type: Static. DM. BST LINK: A link is another major compound object in NS. When a user creates a link using a duplex-link member function of a Simulator object. that all the nodes that will be created are multicast nodes.type: CtrMcast.

Although a user gets enough information from the trace. EnqT. Queue Monitor Basically. and packets dropped at a queue are sent to a Null Agent and are freed there. . Tracing In NS. DrpT and RecvT) receives a packet. DeqT.e. network activities are traced around simplex links. Queue monitoring can be achieved using queue monitor objects and snoop queue objects as shown in Figure 10.e. The trace format will be examined in the General Analysis Example section. tracing objects are designed to record packet arrival time at which they are located. Finally. If the simulator is directed to trace network activities (specified using $ns trace-all file or $ns namtrace-all file). the links created after the command will have the following trace objects inserted as shown in Figure 9. it writes to the specified trace file without consuming any simulation time.Figure 8. Packets dequeued from a queue are passed to the Delay object that simulates the link delay. Link One thing to note is that an output queue of a node is actually implemented as a part of simplex link object. Users can also specifically create a trace object of type type between the given src and dst nodes using the create-trace {type file src dst} command. and passes the packet to the next network object. For example. Figure 9. Inserting Trace Objects When each inserted trace object (i. a user interested in RED queue behavior may want to measure the dynamics of average queue size and current queue size of a specific RED queue (i. he or she might be interested in what is going on inside a specific output queue. need for queue monitoring). the TTL object calculates Time To Live parameters for each packet received and updates the TTL field of the packet.

Packet Flow Example Note that the above figure does not show the exact behavior of a FTP over TCP. It only shows the detailed internals of simulation network setup and a packet flow. and an optional data space (see Figure 12). an FTP application (or traffic source) is attached to the TCP agent. A RED queue monitoring example is shown in the RED Queue Monitor Example section. The network consist of two nodes (n0 and n1) of which the network addresses are 0 and 1 respectively. Note that snoop queue objects can be used in parallel with tracing objects even though it is not shown in the above figure. A TCP agent attached to n0 using port 0 communicates with a TCP sink object attached to n1 port 0. The queue monitor using this information monitors the queue.Figure 10. Monitoring Queue When a packet arrives. Finally. PACKET FLOW EXAMPLE: Until now. the two most important network components (node and link) were examined. PACKET: A NS packet is composed of a stack of headers. a snoop queue object notifies the queue monitor object of this event. Figure 11. Figure 11 shows internals of an example simulation network setup and packet flow. asking to send some amount of data. As briefly mentioned in the "Simple Simulation Example" section. a packet .

RESULT: Thus the details about NS2(Network Simulator 2) has been studied. The second approach is shown as an example in a later section called "Add New Application and Agent". is defined. RTP header (UDP uses RTP header) and trace header. NS Packet Format Usually. This is because it is meaningless to carry data around in a non-real-time simulation. and the offset of each header in the stack is recorded. if you want to implement an application that talks to another application cross the network. . IP header. you might want to use this feature with a little modification in the underlying agent implementation. What this means is that whether or not a specific header is used. Figure 12. However. such as the common header that is commonly used by any objects as needed.header format is initialized when a Simulator object is created. very few application and agent implementations support this. a packet only has the header stack (and a data space pointer that is null). Although a packet can carry actual data (from an application) by allocating a data space. TCP header. where a stack of all registered (or possibly useable) headers. and a network object can access any header in the stack of a packet it processes using the corresponding offset value. Another possible approach would be creating a new header for the application and modifying the underlying agent to write data received from the application to the new header. a stack composed of all registered headers is created when a packet is allocated by an agent.

USE: Network with several hundreds of nodes can be simulated. State and transitions are specified graphically using state-transition diagrams whereas conditions that specify what happen within each state are programmed with a C-like language called Proto-C.. packet switched radio networks. . traffic generators. simulating and analyzing the performance of large communications networks. Common uses are assessing and feasibility of new designs. integrated analysis tools for interpreting and synthesizing output data. The modeling methodology of OPNET is organized in a hierarchical structure. Models are built using a graphical interface. The user cannot define new models. The Analysis Tool provides a graphical environment to view and manipulate data collected during simulation runs. OPNET Planner is an application that allows administrators to evaluate the performance of communications networks and distributed systems. he should contact MIL3's modeling service. No. . no much technical detail are available about the internals. Using a graphical Network Editor.Network Simulator INTRODUCTION: OPNET (Optimized Network Engineering Tools) is a commercial tool from MIL3 Inc. queues. THE PACKAGE The software comprises several tools and is divided in several parts. As everyone should guess. computer systems and applications. Process models are structured as a finite state machine.) are then configured with menus and organized into data flow diagrams that represent nodes using the graphical Node Editor. graphical specification of models and a hierarchical object-based modeling. OPNET is used by companies like Thomson-CSF or CNET which use it to model ATM networks and validate various layers protocols. It is being developed for almost 15 years. Results can be analyzed for any network element. optimizing already developed communication systems and predicting performance. Those processes and built-in modules in OPNET (source and destination modules. Planner analyses behavior and performance by discrete-event simulations. Date: AIM: STUDY OF OPNET To study about OPNET . The user only chooses pre-defined models (from the physical layer to the application) from the library and sets attributes. At the lowest level.Ex. nodes and links are selected to build up the topology of a communication network. OPNET Modeler is intended for modeling. the Model Library.. OPNET Modeler and OPNET Planner. An example of use of OPNET is George Mason University (Quality of Service IP Network Simulation). without programming or compiling. Features included in this generic simulator are an event-driven scheduled simulation kernel. and the Analysis tool. but it would take time for the computation.

OPNET software enables its users to optimize the performance and maximize the availability of communications networks and applications.. priority nonpreemptive queueing. traffic generators. Ethernet. IP. devices. queueing service disciplines such as First-in-First-Out (FIFO). simulating and analysing the performance of large communications networks. nodes and links are selected to build up the topology of a communication network. IPv6. and more. FDDI. OPNET MODULES:  Modeler  Terrain Modeling Module (TMM)  High Level Architecture (HLA) MODELER: OPNET Modeler is intended for modeling. link models such as point-to-point or bus. TCP. Communication Networks. . round-robin or preempt and resume. simulating and analysing the performance of i. OPNET Modeler is the industry's leading environment for network modeling and simulation. optimizing already developed communication systems and predicting performance. . Computer systems and Applications. protocols. Using a graphical Network Editor. has been the leader in developing predictive software solutions for networking professionals. Frame Relay. Modules span a wide range of applications and receive regular updates under OPNET's maintenance program. Process models are structured as a finite state machine. computer systems and applications.The modeling libraries are included with OPNET Modeler and OPNET Planner and contains protocols and analysis environments. The modeling methodology of OPNET is organized in a hierarchical structure. Since 1986.) are then configured with menus and organized into data flow diagrams that represent nodes using the graphical Node Editor. Networking technology has become too complex for traditional analytical methods or "rules of thumb" to yield an accurate understanding of system behavior. allowing you to design and study communication networks. queues. Modeler is used by the world's largest network equipment manufacturers to accelerate the R&D of network devices and technologies such as VoIP. and built-in modules in OPNET (source and destination modules. and applications with unmatched flexibility and scalability. Those processes.. OSPFv3. TCP. Common uses are assessing and feasibility of new designs. MPLS. At the lowest level. OPNET is the state-of-art network simulation tool for modeling. OPNET Technologies Inc. Product modules provide value-added capabilities to OPNET's intelligent network management software. State and transitions are specified graphically using state-transition diagrams whereas conditions that specify what happen within each state are programmed with a C-like language called Proto-C. Last-In-First-Out (LIFO). Distributed Systems ii. among them ATM.. shortest first job.

to exchange messages (interactions). including:  Time management such that an OPNET simulation remains synchronized with overall HLA time  Generation and reception of RTI interactions using OPNET packet  Creation. The OPNETHLA interface provides the various simulators (federates) the necessary mechanisms to share a common object representation (for persistent elements). each modeling some aspect of a composite system. destruction. or discovery of RTI objects during the simulation  Generation of RTI object attribute updates based on changes to OPNET attribute values  Automatic updates of OPNET attributes upon reception of RTI object attribute updates  A user-defined mapping specifying the relation between RTI and OPNET objects RESULT: Thus the Network Simulator-OPNET has been studied. Featuring an open-source Longley-Rice model. The module supports a large subset of the HLA interface. The OPNET HLA Module enables OPNET simulations to model some portion (or the entirety) of the communications aspects of the HLA federation models. Create elevation maps. Interfaces to read DTED and USGS DEM terrain data are provided. the Terrain Modeling Module is ready to replicate any known atmospheric or topological conditions and their combined impact on signal propagation.TERRAIN MODELING MODULE (TMM) Building on the capabilities of OPNET's Wireless Module. line-of-sight profiles. and signalpower comparisons of mobile network models. the Terrain Modeling Module provides the next level of accuracy and control for wireless network design and planning. the Terrain Modeling Module is supported by the standard Radio Transceiver Pipeline. . which enables easy implementation of custom propagation models HIGH LEVEL ARCHITECTURE (HLA) The High-Level Architecture (HLA) Module supports building and running a federation of many simulators. Open and flexible. and to maintain appropriate time synchronization. This module allows you to model environmental effects on wireless network communications anywhere.

Sign up to vote on this title
UsefulNot useful