Escolar Documentos
Profissional Documentos
Cultura Documentos
Date:
ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Read the data from the client and continue till the string bye is entered. 9. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Send the data to the server and wait for the server to reply til the user enters bye. 6. Close the connected socket.
Result: Thus the program to implement TCP chat client server was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc Chat_server.c [network@server Network]$ ./a.out Enter the port address: 2134 Socket is created successfully Bind successful Accept successful Hi bye Client Side: [network@server Network]$ cc Chat_client.c [network@server Network]$ ./a.out Enter the port address: 2134 Socket is created successfully Connected Hi
Date:
ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Retrieve time information and send it to the client through the connected socket. 9. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Give request to obtain time information. 6. Read the information and print it. 7. Close the connected socket.
while((n=read(sockfd,recvline,sizeof(recvline)-1))>0) { recvline[n]=0; if(fputs(recvline,stdout)==EOF) { perror("Error in fputs()"); exit(1); } } if(n<0) { perror("Error while read"); exit(1); } exit(0); }
Result: Thus the program to implement TCP daytime server client was written successfully and the output was verified.
Output:
Server Side: [network@serverNetwork]$ cc Date_server.c [network@serverNetwork]$ ./a.out Client Side: [network@serverNetwork]$ cc Date_client.c [network@serverNetwork]$ ./a.out Today the day time and date is: Mon Jul 18 09:48:09 2010
Date:
ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Echo the received information from the connected socket. 9. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Read the message to be echoed from the user. 6. Send it to the server and read the response that comes back from the server. 7. Print the response received from the server. 8. Close the connected socket.
printf("\nMessage recived and echoed:%s\n",buffer); write(conn_s,buffer,strlen(buffer)); if(close(conn_s)<0) { fprintf(stderr,"\nECHOSERV: Error in calling close()\n"); exit(EXIT_FAILURE); } else { printf("Connection closed\n"); exit(EXIT_SUCCESS); } } }
Result:
Thus the program to implement echo server was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc echoserver.c [network@server Network]$ ./a.out Enter the port address: 2134 Client Side: [network@server Network]$ cc echoclient.c [network@server Network]$ ./a.out 172.16.6.200 2134 Remote host address: 172.16.6.200 Remote port address: 2134 Enter the string to be echoed: Check Echo response: Check
Date:
ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Read the domain name from the client. 9. Search for the given domain name in dns_map.txt and send the corresponding IP address to the client. 10. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Read the domain name from the user. 6. Send the domain name and receive the IP address. 7. Print the received IP address. 8. Close the connected socket.
Filename:
dns_map.txt
Result: Thus the program to implement DNS was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc DNS_server.c [network@server Network]$ ./a.out Enter the port address: 2950 Socket is created Bind success Connection successful localhost1 Sending the IP address Client Side: [network@server Network]$ cc DNS_client.c [network@server Network]$ ./a.out Enter the port address: 2950 Socket is creation successfully Connected Enter the domain name: localhost1 The IP address is: 172.16.6.201
Date:
Aim: To write a program in C to implement UDP client server chat. Algorithm: UDP Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Retrieve information from Socket. 7. Echo retrieved information to socket 8. Close the connected socket. UDP Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Close the connected socket.
Result: Thus the program to implement UDP Chat server was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc UDP_server.c [network@server Network]$ ./a.out Creating datagram socket Socket created successfully Assigned port address: 32775 Waiting for a message to arrive Data has been sent to socket The message was: Hi. How are you? Closing the socket connection Socket closed Client Side: [network@server Network]$ cc UDP_client.c [network@server Network]$ ./a.out 172.16.6.200 32775 Creating datagram socket Socket created successfully Data: Hi. How are you? Sending data to socket Data has been sent to socket Closing socket connection Socket closed
Date:
AIM: To write a C program to implement Sliding Window protocol of type go back n. ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Read the message from the user and transmit it to the client. 9. Read the status of the transmitted frame; in each case of error retransmit all the frames from the error frame till the last sent frame. 10. Repeat previous step until the whole message is received by the client. 11. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Read a frame from the server. 6. Check the received frame and report error if any. 7. Repeat the previous step until the message is error-free. 8. Receive the next frame from the server and continue the previous two steps till end. 9. Close the connected socket.
printf("\nTransmission successful"); else { printf("Received error in: %d", status); printf("\nRetransmitting frames"); for(j=0;;) { frame[j] = str[j+status]; j++; printf("%d", j+status); if((j+status)%4 == 0) break; } printf("\n"); frame[j] = '\0'; len = strlen(frame); for(j=0; j<len; j++) { sprintf(temp, "%d", j+status); strcat(frame, temp); } write(lfd, frame, sizeof(frame)); } i = i + SIZE; } write(lfd, "Exit", sizeof("Exit")); printf("\nExitting!\n"); sleep(2); close(lfd); close(std); }
Result: Thus the program to implement Sliding Window protocol of type Go back n was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc GN_server.c [network@server Network]$ ./a.out Enter the port address: 1250 Enter text: TrialText Transmitting frames: 0123 Received error at 0 Retransmitting frames: 1234 Transmitting frames: 4567 Transmission successful Transmitting frames: 8 Transmission successful Exiting Client Side: [network@server Network]$ cc GN_client.c [network@server Network]$ ./a.out Enter the port address: 1250 Received: Tria0123 Do you want to report an error(1-Yes, 2-No): 1 Enter the seq no of the frame: 0 Received the retransmitted frame: Tria0123 Received: lTex4567 Do you want to report an error(1-Yes, 2-No): 0 Received: t8 Do you want to report an error(1-Yes, 2-No): 0 Exiting
Date:
AIM: To write a C program to implement Sliding Window protocol of type selective repeat. ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Read the message from the user and transmit it to the client. 9. Read the status of the transmitted frame; in each case of error retransmit the particular frame. 10. Repeat previous step until the whole message is received by the client. 11. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Read a frame from the server. 6. Check the received frame and report error if any. 7. Repeat the previous step until the message is error-free. 8. Receive the next frame from the server and continue the previous two steps till end. 9. Close the connected socket.
printf("\nTransmission successful"); else { printf("Received error in: %d", status); printf("\nRetransmitting frame"); frame[0] = str[status]; frame[1] = '\0'; write(lfd, frame, sizeof(frame)); } i = i + SIZE; } write(lfd, "Exit", sizeof("Exit")); printf("\nExitting!\n"); sleep(2); close(lfd); close(std); }
Result: Thus the program to implement Sliding Window protocol of type selective repeat was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc SR_server.c [network@server Network]$ ./a.out Enter the port address: 1250 Enter text: Hello Transmitting frames: 0123 Received error at 2 Retransmitting frame Transmitting frames: 4 Transmission successful Exiting Client Side: [network@server Network]$ cc SR_client.c [network@server Network]$ ./a.out Enter the port address: 1250 Received: Hell0123 Do you want to report an error(1-Yes, 2-No): 1 Enter the seq no of the frame: 2 Received the retransmitted frame: l Received: o4 Do you want to report an error(1-Yes, 2-No): 0 Exiting
Date:
AIM: To write a C program to implement remote procedure call. ALGORITHM: Server: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for server. 4. Bind socket with addresses. 5. Specify number of allowed connection. 6. Wait for connection. 7. Accept connection (If any). 8. Define a procedure convert to toggle the case of characters supplied by the client. 9. Read the data to be operated to be by the procedure. 10. Invoke the procedure with the parameters and store the return value in the buffer. 11. Send the value in the buffer to the client. 12. Close the connected socket. Client: 1. Include necessary header files to support functions for socket definition, socket types, internet addresses, I/O functions, UNIX system calls. 2. Declare variables for socket ID, port number, socket addresses, character buffer, etc. 3. Create socket for client. 4. Connect client socket to the server socket addresses. 5. Read the string to be converted from the user. 6. Send the parameter to the server. 7. Receive the output string and display it to the user. 8. Close the connected socket.
if(listen(list_s, 8)<0) { fprintf(stderr, "ECHOSERV: Error in listen\n"); exit(EXIT_FAILURE); } while(1) { if((conn_s = accept(list_s, NULL, NULL))<0) { fprintf(stderr, "ECHOSERV:Error in calling accept\n"); exit(EXIT_FAILURE); } strcpy(buffer, " "); read(conn_s, buffer, 20); convert(buffer); write(conn_s, buffer, 20); if(close(conn_s)<0) { fprintf(stderr, "ECHOSERV: Error in close()\n"); exit(EXIT_FAILURE); } else exit(EXIT_SUCCESS); } }
return EXIT_SUCCESS; }
Result: Thus the program to implement remote procedure call was written successfully and the output was verified.
Output:
Server Side: [network@server Network]$ cc RPC_server.c [network@server Network]$ ./a.out Enter the server port: 3000 Remote Host Address: 172.16.6.200 Remote Port No: 3000 Enter the string to tOGGLE case: TrialTEXT The string with changed case is: tRIALtext Client Side: [network@server Network]$ cc RPC_client.c [network@server Network]$ ./a.out 172.16.6.200 3000
Date:
Aim: To write a program to implement Address Resolution Protocol to obtain MAC address. Algorithm: Server: 1. Start 2. Create a shared memory based on the key value. 3. It is attached to memory at next available space using shmat() 4. Print table that contains IP address and MAC address. 5. After client is invoked, use the shared memory to enter the key and IP address 6. Search is made on the table for IP address. 7. If exists, then corresponding MAC address is written in the shared memory. 8. Stop. Client: 1. Start 2. After shared memory is created is created using shmget. 3. Enter the IP address into the shared memory. The key value is 7000. 4. The entered IP address is sent to the server and its corresponding MAC address is written to the shared memory by the server. 5. The stored MAC address is printed by the client. 6. If the IP address is not available then error message is displayed. 7. Stop.
Address Resolution Protocol Filename: ARP_server.c Server program Code: #include<stdio.h> #include<sys/shm.h> #include<sys/ipc.h> #include<string.h> main() { char ip[10], *ptr, *dest, table[6][20] = {"1:A1:2E:3:4:5", "1.1.1.3", "1:B1:C3:D2:49:5", "1.1.1.4"}; int shmid, shmid1, shmid2, key, i, *flag; shmid1 = shmget(6000, sizeof(int), IPC_CREAT|0666); flag = shmat(shmid1, NULL, 0); printf("IP\t\tMAC"); for(i=0;i<4;i+=2) printf("\n%s\t\t%s", table[i], table[i+1]); while(1) { printf("Enter the key and the IP address"); scanf("%d%s", &key, ip); *flag = 0; shmid2 = shmget(key, 30, 0666); dest = shmat(shmid2, NULL, 0); for(i = 1; i<4; i+=2) if(!strcmp(ip, table[i])) break; if(i>4) dest = '\0'; else strcpy(dest, table[i-1]); } printf("Exiting!"); }
Filename: ARP_client.c Client program Code: #include<stdio.h> #include<sys/shm.h> #include<sys/ipc.h> #define key 7000 main() { int shmid, shmid1, shmid2, *flag; char *bus, *local, ip[20]; shmid = shmget(6000, 30, 0666); bus = shmat(shmid1, NULL, 0); shmid1 = shmget(key, 30, IPC_CREAT|0666); flag = shmat(shmid1, NULL, 0); if((shmid2 = shmget(key, 30, IPC_CREAT|0666))<0) perror("Error!"); local = shmat(shmid2, NULL, 0); printf("Enter the IP address:"); scanf("%s", ip); sprintf(bus, "%d%s", key, ip); *flag = 1; while(*flag == 1); if(*local == '\0') printf("IP address is invalid"); else printf("The MAC address is: %s", local); }
Result:
Thus the program to implement Address Resolution Protocol to obtain MAC address was written successfully and the output was verified.
Output:
Server side: [network@server Network]$ cc ARP_server.c [network@server Network]$ ./a.out MAC IP 1.1.1.3 1:A1:2E:3:4:5 1.1.1.4 1:B1:C3:D2:49:5 Enter the key and the IP address7000 1.1.1.3 Enter the key and the IP address
Client side: [network@server Network]$ cc ARP_client.c [network@server Network]$ ./a.out Enter the IP address:1.1.1.3
Date:
To write a program to implement Reverse Address Resolution Protocol to obtain IP address. Algorithm: Server: 1. Start 2. Create a shared memory based on the key value. 3. It is attached to memory at next available space using shmat() 4. Print table that contains IP address and MAC address. 5. After client is invoked, use the shared memory to enter the key and MAC address 6. Search is made on the table for MAC address. 7. If exists, then corresponding IP address is written in the shared memory. 8. Stop. Client: 1. Start 2. After shared memory is created is created using shmget. 3. Enter the MAC address into the shared memory. The key value is 7000. 4. The entered MAC address is sent to the server and its corresponding IP address is written to the shared memory by the server. 5. The stored IP address is printed by the client. 6. If the MAC address is not available then error message is displayed. 7. Stop.
Reverse Address Resolution Protocol Filename: RARP_server.c Server program Code: //Program to implement RARP. #include<stdio.h> #include<sys/shm.h> #include<sys/ipc.h> #include<string.h> main() { char mac[10], *ptr, *dest, table[6][20] = {"1.1.1.3", "1:A1:2E:3:4:5", "1.1.1.4", "1:B1:C3:D2:49:5"}; int shmid, shmid1, shmid2, key, i, *flag; shmid1 = shmget(6000, sizeof(int), IPC_CREAT|0666); flag = shmat(shmid1, NULL, 0); printf("IP\t\tMAC"); for(i=0;i<4;i+=2) printf("\n%s\t\t%s", table[i], table[i+1]); while(1) { printf("Enter the key and the MAC address"); scanf("%d%s", &key, mac); *flag = 0; shmid2 = shmget(key, 30, 0666); dest = shmat(shmid2, NULL, 0); for(i = 1; i<4; i+=2) if(!strcmp(mac, table[i])) break; if(i>4) dest = '\0'; else strcpy(dest, table[i-1]); } printf("Exiting!"); }
Filename: RARP_client.c Client program Code: //Program to implement RARP. #include<stdio.h> #include<sys/shm.h> #include<sys/ipc.h> #define key 7000 main() { int shmid, shmid1, shmid2, *flag; char *bus, *local, mac[20]; shmid = shmget(6000, 30, 0666); bus = shmat(shmid1, NULL, 0); shmid1 = shmget(key, 30, IPC_CREAT|0666); flag = shmat(shmid1, NULL, 0); if((shmid2 = shmget(key, 30, IPC_CREAT|0666))<0) perror("Error!"); local = shmat(shmid2, NULL, 0); printf("Enter the MAC address:"); scanf("%s", mac); sprintf(bus, "%d%s", key, mac); *flag = 1; while(*flag == 1); if(*local == '\0') printf("MAC address is invalid"); else printf("The IP address is: %s", local); }
Result:
Thus the program to implement Address Resolution Protocol to obtain IP address was written successfully and the output was verified.
Output: Server side: [network@server Network]$ cc RARP_server.c [network@server Network]$ ./a.out IP MAC 1.1.1.3 1:A1:2E:3:4:5 1.1.1.4 1:B1:C3:D2:49:5 Enter the key and the MAC address7000 1:A1:2E:3:4:5 Enter the key and the MAC address Client side: [network@server Network]$ cc RARP_client.c [network@server Network]$ ./a.out Enter the MAC address:1:A1:2E:3:4:5
Date:
Aim: To simulate the Open Shortest Path First routing protocol based on the cost assigned to each path. Algorithm: 1. Read the number of nodes, n. 2. Read the cost matrix for the path from each node to another node. 3. Initialize SOURCE to 1 and DEST to 1. 4. Compare D of a node which is the distance from source to that corresponding node. 5. Repeat steps 6 to 8 for n-1 nodes. 6. Choose the node that has not be included compare the distance to reach the node using the newly included node. 7. Take the minimum value as the new distance. 8. Print the distance of the given path calculated by the program and the path. 9. Read further source and destination from the user to calculate the shortest path. 10. Exit when the user chooses -1 for source and destination.
Open Shortest Path First Routing Protocol Filename: OSPF.c Program Code: #include <stdio.h> #include <conio.h> #define INFINITY 0x7FFF
static int adj[20][20]; int dist[20], previous[20], unoptimized[20], n; void Init(); int UnoptimizedNodeExists(); void FindShortest(int src); void main() { int wt, stack[20], top=0, src, dst, v; clrscr(); AskNumberOfNodes: printf("Enter the number of nodes (max 20): "); scanf("%d", &n); if(n>20) { printf("\nSorry, so many are not allowed. Try again!\n"); goto AskNumberOfNodes; } printf("\nEnter the edges one by one. -1, -1 to stop.\n"); while(1) { printf("\nSource\t\t: "); scanf("%d", &src); printf("Destination\t: "); scanf("%d", &dst); if(src==-1 && dst==-1) break; if(src<1 || src>n || dst<1 || dst>n) { printf("\nInvalid input\n"); continue; } src--; dst--; printf("Edge weight\t: "); scanf("%d", &wt);
if(wt<1) { printf("\nWeight must be atleast 1! Edge neglected.\n"); continue; } adj[src][dst]=adj[dst][src]=wt; } printf("\nTo find shortest path... use -1, -1 to stop.\n"); while(1) { printf("\nEnter source and destination nodes: "); scanf("%d%d", &src, &dst); if(src==-1 && dst==-1) break; if(src<1 || src>n || dst<1 || dst>n) { printf("\nInvalid input\n"); continue; } src--; dst--; FindShortest(src); v=dst; while(v!=(-1)) { stack[top]=v; top++; v=previous[v]; } if(top==1 && src!=dst) printf("\nSorry no such path found!\n"); else { printf("\n"); while(top) { top--; printf("%d - ", stack[top]+1); } printf("\b\b \n"); } } }
void Init() { int i; for(i=0; i<n; i++) { previous[i]=(-1); dist[i]=INFINITY; unoptimized[i]=1; } } int UnoptimizedNodeExists() { int i; for(i=0; i<n; i++) { if(unoptimized[i]) return 1; } return 0; } void FindShortest(int src) { int i, alt, u=src, v, minDistance; // Initialize prev[], dist[] and // Q := the set of all nodes in Graph ; Init(); // dist_between(source, source) is obviously zero dist[src]=0; while(UnoptimizedNodeExists()) { minDistance = INFINITY; // u := vertex in Q with smallest dist[] ; for(i=0; i<n; i++) { if(unoptimized[i] && dist[i]<minDistance) { u=i; minDistance=dist[i]; } }
if(minDistance == INFINITY) { printf("\nOne or more isolated node(s) found!\n"); break; } // Remove u from Q unoptimized[u]=0; // For each neighbor v of u: for(v=0; v<n; v++) { // (where v is not removed from Q) if(adj[u][v] && unoptimized[v]) { alt = dist[u] + adj[u][v]; if(alt<dist[v]) { dist[v]=alt; previous[v]=u; } } } } }
Output: Enter the number of nodes (max 20): 5 Enter the edges one by one. -1, -1 to stop. Source :1 Destination : 2 Edge weight : 1 Source :2 Destination : 5 Edge weight : 6 Source :2 Destination : 4 Edge weight : 1 Source :2 Destination : 3 Edge weight : 3 Source :5 Destination : 4 Edge weight : 4 Source :3 Destination : 4 Edge weight : 2 Source :1 Destination : 3 Edge weight : 5 Source : -1 Destination : -1 Graph Structure
To find shortest path... use -1, -1 to stop. Enter source and destination nodes: 1 5 1-2-4-5 Enter source and destination nodes: 1 4 1-2-4 Enter source and destination nodes:-1 -1
Result:
Thus the program to simulate the Open Shortest Path First routing protocol based on the cost assigned to each path was implemented successfully and the output was verified.
Ex No:10(a)
Aim: To study the performance of TCP based network by considering the bandwidth.
Procedure: 1. Start 2. Set a simulator variable (ns). 3. Set the animator file and the trace file to simulator. 4. Create nodes for the network topology. 5. Design the topology by connecting the nodes with required links and desirable orientation. 6. Add TCP agent to a specific node and assign another node as the sink. 7. Create the Application level traffic, File Transfer (FTP), to represent the data flow. 8. Record the data rate at every interval of 0.5 seconds and store the contents in a trace file. 9. Use this trace file to draw a performance graph. 10. Close all the instances of ns and trace files. 11. Initiate the animator (nam) 12. Simulate the designed network. 13. Verify the output. 14. Stop
Study of TCP Performance using Network Simulator Filename: TCP.tcl Program Code: set ns [new Simulator] set nf [open out.nam w] $ns namtrace-all $nf set tf [open out.tr w] proc finish {} { global ns nf tf $ns flush-trace close $nf close $tf exec nam out.nam & exec xgraph -x Time -y Bandwidth out.tr & exit 0 } proc record {} { global sink tf #Get an instance of the simulator set ns [Simulator instance] #Set the time after which the procedure should be called again set time 0.5 #How many bytes have been received by the traffic sinks? set bw0 [$sink set bytes_] #Get the current time set now [$ns now] #Calculate the bandwidth (in MBit/s) and write it to the files puts $tf "$now [expr $bw0/$time*8/100000]" #Reset the bytes_ values on the traffic sinks $sink set bytes_ 0 #Re-schedule the procedure $ns at [expr $now+$time] "record" } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n3 1Mb 10ms DropTail $ns duplex-link $n2 $n3 1Mb 10ms DropTail $ns duplex-link-op $n0 $n2 orient right-up $ns duplex-link-op $n1 $n3 orient right $ns duplex-link-op $n2 $n3 orient left-up $ns queue-limit $n1 $n3 4 $ns duplex-link-op $n2 $n3 queuePos 0.5 set tcp [new Agent/TCP] $ns attach-agent $n0 $tcp set sink [new Agent/TCPSink] $ns attach-agent $n1 $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.0 "record" $ns at 0.2 "$ftp start" $ns at 4.5 "$ftp stop" $ns at 5.0 "finish" $ns run
Output:
Ex No: 10(b)
Aim: To study the performance of an UDP based network by considering the data rate of the packets sent.
Procedure: 1. Start 2. Set a simulator variable (ns). 3. Set the animator file and the trace file to simulator. 4. Create nodes for the network topology. 5. Design the topology by connecting the nodes with required links and desirable orientation. 6. Add UDP agent to a specific node and assign another node as the sink. 7. The data (traffic) flows from the agent to the sink. 8. Create the Application level traffic, Constant Bit Rate (CBR), to represent the data flow. 9. Record the data rate at every interval of 0.5 seconds and store the contents in a trace file. 10. Use this trace file to draw a performance graph. 11. Close all the instances of ns and trace files. 12. Initiate the animator (nam); 13. Simulate the designed network. 14. Verify the output. 15. Stop.
Study of UDP Performance using Network Simulator Filename: UDP.tcl Program code: set ns [new Simulator] set nf [open out.nam w] $ns namtrace-all $nf set tf [open out.tr w] proc finish {} { global ns nf tf $ns flush-trace close $nf close $tf exec nam out.nam & exec xgraph -x Time -y DataRate out.tr & exit 0 }
proc record {} { global tf source appl set ns [Simulator instance] #Set the time after which the procedure should be called again set time 2.0 #Get the current time set now [$ns now] #Get the data rate and write it to the files puts $tf "$now [$appl set rate_]" #Re-schedule the procedure $ns at [expr $now+$time] "record" } set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n3 1Mb 10ms DropTail $ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link-op $n0 $n2 orient right-up $ns duplex-link-op $n1 $n3 orient right $ns duplex-link-op $n2 $n3 orient left-up $ns queue-limit $n2 $n3 4 #$ns duplex-link-op $n4 $n5 queuePos 0.5 set source [new Agent/UDP] $ns attach-agent $n0 $source $source set packetSize 10 set dest [new Agent/Null] $ns attach-agent $n1 $dest $ns connect $source $dest set appl [new Application/Traffic/CBR] $appl attach-agent $source $appl set random_ true $ns at 0.0 "record" $ns at 0.5 "$appl start" $ns at 3.5 "$source set packetSize_ 45" $ns at 4.5 "$appl stop" $ns at 5.0 "finish" $ns run
Output: