Computer Networks Lab Manual - Google Groups

1 downloads 141 Views 126KB Size Report
break; printf("Enter the Message.\n"); //get message from keybrd. len = read(1, msg, 100) - 1; .... What is the use of a
06CSL77: Networks Laboratory Manual

C/C++ Programs

NETWORKS LABORATORY Sub Code : 06CSL77 Note : Student is required to solve one problem from PART-A and one problem from PART-B. Both the parts have equal marks.

PART A – Simulation Exercises The following experiments shall be conducted using either NS/OPNET or any other simulators. 1. Simulate a three nodes point-to-point network with duplex links between them. Set the queue size vary the bandwidth and find the number of packets dropped. 2. Simulate a four node point-to-point network, and connect the links as follows: n0-n2, n1-n2 and n2-n3. Apply TCP agent between n0-n3 and UDP n1-n3. Apply relevant applications over TCP and UDP agents changing the parameter and determine the number of packets by TCP/UDP. 3. Simulate the different types of Internet traffic such as FTP a TELNET over a network and analyze the throughput. 4. Simulate the transmission of ping messaged over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion. 5. Simulate an Ethernet LAN using N-nodes(6-10), change error rate and %d ", ct[i]); } printf("\nPlain Text="); for (i = 0; i < len; i++) { pt[i] = multi(ct[i], d, printf("%c", pt[i]); } printf("\n");

C/C++ Programs

//convert plain to cipher text n);

//convert cipher to plain text n);

} Output: $ gcc rsa.c $ ./a.out Enter 2 large prime numbers p & q:23 11 Enter prime value of e relative to 220(z):113 Enter the Message computer networks Cipher Text=44 166 175 19 123 139 85 229 131 220 85 139 179 166 229 17 92 Plain Text=computer networks

KJ Author: Karthik Jain H J YDIT(CS)

Page: 11/15

06CSL77: Networks Laboratory Manual

7) Write a correction.

program

for

C/C++ Programs

Hamming

Code

generation

for

error

detection

and

//hamming.c #include char data[4]; int encoded[7], edata[7], syn[3], i = 0; int hmatrix[3][7] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1}; int gmatrix[4][7] = {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1}; int main() { int i, j; printf("Enter 4 bit data: "); scanf("%s", data); printf("Encoded Data: "); for (i = 0; i < 7; i++) { for (j = 0; j < 4; j++) encoded[i] += ((data[j])*(gmatrix[j][i])); encoded[i] = encoded[i] % 2; printf("%d ", encoded[i]); } printf("\nEnter Encoded bits as received : "); for (i = 0; i < 7; i++) scanf("%d", &edata[i]); for (i = 0; i < 3; i++) { //Generating Syndrome matrix for (j = 0; j < 7; j++) syn[i] += (hmatrix[i][j] * edata[j]); syn[i] = syn[i] % 2; } for (i = 0; i < 7; i++) //finding Error Bit if (syn[0] == hmatrix[0][i] && syn[1] == hmatrix[1][i] && syn[2] == hmatrix[2][i]) break; if (i == 7) printf("Data is error free!!\n"); else { printf("Error in data at bit position: %d\n", i + 1); edata[i] = !edata[i]; //Complementing the bit value printf("The Correct data Should be : "); for (i = 0; i < 7; i++) printf("%d ", edata[i]); printf("\n"); } return 0; } Output: $ gcc hamming.c $ ./a.out [ENCODING] Enter 4 bit data: Encoded Data: 0 1 0 1 0 1 1 [DECODING]Enter Encoded bits Error received at bit number The Correct data Should be :

1011 as received : 0 1 0 1 0 1 0 7 of the data 0 1 0 1 0 1 1

KJ Author: Karthik Jain H J YDIT(CS)

Page: 12/15

06CSL77: Networks Laboratory Manual

C/C++ Programs

8) Write a program for congestion control using Leaky bucket algorithm. //LeakyBucket.c #include //IF U want the count of time elapsed remove the comments :) //int time=0; void bktInput(int a, int b, int size) { if (a > size) printf("\tBucket overflow.\n"); else { sleep(1); //Generate equal time delay // time++; while (a > b) { // printf("Time: %dseconds\n",time); printf("\t%d bytes outputted\n", b); a -= b; sleep(1); //Generate equal time delay // time++; } // printf("Time: %dseconds\n",time); if (a > 0) printf("\tLast %d bytes sent\n", a); printf("\tBucket output successful.\n"); } } int main() { int op, pktSize, i, bktsize, n, delay; printf("bucket Size : "); scanf("%d", &bktsize); printf("Output Rate : "); scanf("%d", &op); printf("No of packets : "); scanf("%d", &n); for (i = 0; i < n; i++) { delay = (rand() % 10); //Generate random rate of packet sleep(delay); //sleep(No_Of_Seconds); // time+=dealy; pktSize = rand() % 1000; // printf("Time: %dseconds\n",time); printf("Packet no %d\tPacket size = %d\n", i, pktSize); bktInput(pktSize, op, bktsize); } return 0; } Output: $ gcc LeakyBucket.c $ ./a.out bucket Size : 512 Output Rate : 128 No of packets : 3 Packet no 0 Packet size = 886 Bucket overflow . Packet no 1 Packet size = 103 Last 103 bytes sent Bucket output successful. Packet no 2 Packet size = 207 128 bytes outputted Last 79 bytes sent Bucket output successful. Author: Karthik Jain H J YDIT(CS)

KJ Page: 13/15

06CSL77: Networks Laboratory Manual

C/C++ Programs

Viva Questions. 1. Describe bind(), listen(), accept(),connect(), send() and recv(). 2. Differentiate between Connectionless & connection oriented connection. 3. Differentiate between flow control and congestion control. 4. Differentiate between Leaky bucket and Token bucket. 5. Differentiate between logical and physical address. 6. Differentiate between Point-to-Point Connection and End-to-End connections. 7. Differentiate between Prim’s and Kruskal’s algorithm. 8. Differentiate between route, bridge, switch and hub. 9. Differentiate between Simulation and Emulation. 10. Differentiate between TCP and UDP. 11. Differentiate between TCP/IP Layers and OSI Layers 12. Explain mkfifo(), open(), close() with parameters. 13. How do you classify congestion control algorithms? 14. How do you classify cryptographic algorithms? 15. How do you classify routing algorithms? Give examples for each. 16. How do you generate busty traffic? 17. How do you generate multiple traffics across different sender receiver pairs? 18. How do you implement Leaky bucket? 19. How do you overcome count to infinity problem? 20. How do you setup Ethernet LAN? 21. How routers update distances to each of its neighbor? 22. Name few other Network simulators 23. What are advantages of simulation? 24. What are dispatcher, coordinator and nctunsclient? 25. What are drawbacks in distance vector algorithm? 26. What are ephemerical port number and well known port numbers? 27. What are functions of different layers? 28. What are key, ciphertext and plaintext? 29. What are protocols running in different layers? 30. What are Routing algorithms? 31. What are system calls? Mention few of them. 32. What are the other error detection algorithms? 33. What are the parameters of socket()? 34. What is a socket? 35. What is an IP address? 36. What is BER? 37. What is BSS? 38. What is collision? 39. What is cryptography? 40. What is difference between CRC and Hamming code? 41. What is encapsulation? 42. What is FTP? 43. What is generator matrix? 44. What is ICMP? What are uses of ICMP? Name few. 45. What is incoming throughput and outgoing throughput? 46. What is IPC? Name three techniques. Author: Karthik Jain H J YDIT(CS)

Page: 14/15

KJ

06CSL77: Networks Laboratory Manual

C/C++ Programs

47. What is MAC address? 48. What is meant by bridge? 49. What is meant by congestion window? 50. What is meant by file descriptor? 51. What is meant by Gateway? 52. What is meant by hub? 53. What is meant by mobile host? 54. What is meant by NCTUns? 55. What is meant by port? 56. What is meant by router? 57. What is meant by subnet? 58. What is meant by switch? 59. What is meant by syndrome? 60. What is meant by traffic shaping? 61. What is MTU? 62. What is odd parity and even parity? 63. What is ping and telnet? 64. What is private key? 65. What is Protocol Stack? 66. What is public key? 67. What is simulation? 68. What is spanning tree? 69. What is the polynomial used in CRC-CCITT? 70. What is the use of adding header and trailer to frames? 71. Where Pirm’s algorithm does finds its use in Networks? 72. Which address gets affected if a system moves from one place to another place? 73. Which layer implements security for data? 74. Which layer imposes MTU? 75. Why fragmentation requires? 76. Why frame sorting is required? 77. Why Hamming code is called 7,4 code? 78. Why header is required? 79. Why IP address is required when we have MAC address?

KJ Author: Karthik Jain H J YDIT(CS)

Page: 15/15