You are on page 1of 34

AMRUTA INSTITUTE OF ENGINEERING AND MANAGEMENT SCIENCES

CN Lab Manual
7 sem laboratory work(10CSL77) AIeMS
5/11/2013

This manual is for 7 Semester Computer Science and Information Science students (under VTU, Belgaum) to carry out their network lab programs. Network Simulator used is NCTUNS.

CN Lab Manual
Networks Laboratory Subject Code: 10CSL77 Hours/Week : 03 Total Hours : 42 I.A. Marks : 25 Exam Hours: 03 Exam Marks: 50

Note: Student is required to solve one problem from PART-A and one problem from PART-B. The questions are allotted based on lots. Both questions carry equal marks. PART A ( Simulation Programs) 1. Simulate a three nodes point to point network with duplex links between them. Set the queue size and vary the bandwidth and find the number of packets dropped. 2. Simulate a four node point-to-point network with the links connected as follows: n0 n2, n1 n2 and n2 n3. Apply TCP agent between n0-n3 and UDP between n1-n3. Apply relevant applications over TCP and UDP agents changing the parameter and determine the number of packets sent by TCP / UDP. 3. Simulate the transmission of ping messages over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion. 4. Simulate an Ethernet LAN using n nodes (6-10), change error rate and data rate and compare throughput. 5. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination. 6. Simulate simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets. PART B ( C/C++ Programs) 7. Write a program for error detecting code using CRC-CCITT (16- bits). 8. Write a program for distance vector algorithm to find suitable path for transmission. 9. Using TCP/IP sockets, write a client server program to make the client send the file name and to make the server send back the contents of the requested file if present. 10. Implement the above program using as message queues or FIFOs as IPC channels. 11. Write a program for simple RSA algorithm to encrypt and decrypt the data. 12. Write a program for congestion control using leaky bucket algorithm.

Department of CSE/ISE, AIeMS,Bangalore

Page 2

CN Lab Manual
Network simulators implemented in software are valuable tools for researchers to develop, test, and diagnose network protocols. Simulation is economical because it can carry out experiments without the actual hardware. It is flexible because it can, for example, simulate a link with any bandwidth and propagation delay or a router with any queue size and queue management policy. Simulation results are easier to analyze than experimental results because important information at critical points can be easily logged to help researchers diagnose network protocols. Network simulators, however, have their limitations. A complete network simulator needs to simulate networking devices (e.g., hosts and routers) and application programs that generate network traffic. It also needs to provide network utility programs to configure, monitor, and gather statistics about a simulated network. Therefore, developing a complete network simulator is a large effort. Due to limited development resources, traditional network simulators usually have the following drawbacks: Simulation results are not as convincing as those produced by real hardware and software equipment. In order to constrain their complexity and development cost, most existing network simulators can only simulate reallife network protocol implementations with limited detail, and this can lead to incorrect results. For example, OPNETs modeler produ ct uses a simplified finite state machine model to model complex TCP protocol processing. As another example, in ns-2 package, it is documented that there is no dynamic receivers advertised window for TCP. The NCTUNS uses a distributed architecture to support remote simulations and concurrent simulations. It also uses open-system architecture to enable protocol modules to be easily added to the simulator. Functionally, it can be divided into eight separate components described below: The first component is the fully-integrated GUI environment by which a user can edit a network topology, configure the protocol modules used inside a network node, specify mobile nodes' moving paths, plot performance curves, play back animations of logged packet transfers, etc. From a network topology, the GUI program can generate a simulation job description file suite. Since the GUI program uses Internet TCP/IP sockets to communicate with other components, it can submit a job to a remote simulation machine for execution. When the simulation is finished, the simulation results and generated log files are transferred back to the GUI program. The user then can either examine logged data, plot performance curves, or play back packet transfer animations etc. While a simulation is running at the remote simulation machine, the user can query or set an objects value at any time. For example, the user may query or set the routing table of a router or the switch table of a switch at any time. If the user does not want to do any query or set operation during a simulation, the user can choose to disconnect the currently running simulation so that he (she) can use the GUI program to handle other simulation cases. The user can later reconnect to a disconnected simulation at any time, whether it is still running or has finished. A user thus can submit many simulation jobs in a short period of time. This can increase simulation throughput if there are many simulation machines available to service these jobs concurrently. The second component is the simulation engine. A simulation engine is a user-level program. It functions like a small operating system. Through a defined API, it provides useful and basic simulation services to protocol modules.Such services include virtual clock maintenance, timer management,

Department of CSE/ISE, AIeMS,Bangalore

Page 3

CN Lab Manual
event scheduling, variable registrations, etc. The simulation engine needs to be compiled with various protocol modules to form a single user-level program, which we call the simulation server. When executed to service a job, the simulation server takes a simulation job description file suite as its input, runs the simulation, and generates data and packet transfer log files as its output. When a simulation server is running, because it needs to use a lot of kernel resources, no other simulation server can be running at the same time. The third component is various protocol modules. A protocol module is like a layer of a protocol stack. It performs a specific protocol or function. For example, the ARP protocol or a FIFO queue is implemented as a protocol module. A protocol module is composed of a set of functions. It needs to be compiled with the simulation engine to form a simulation server. Inside the simulation server, multiple protocol modules can be linked into a chain to form a protocol stack. The fourth component is the simulation job dispatcher, which is a userlevel program. It should be executed and remain alive all the time to manage multiple simulation machines. We use it to support concurrent simulations on multiple simulation machines. The job dispatcher can operate between a large number of GUI users and a large number of simulation machines. When a user submits a simulation job to the job dispatcher, the dispatcher will select an available simulation machine to service this job. If there is no available machine at this time, the submitted job can be queued in the dispatcher as a background job. Background jobs are managed by the dispatcher. Various scheduling policies can be used to schedule their service order. The fifth component is the coordinator, which is a user level program. On every machine where a simulation server program resides, a coordinator program needs to be executed and remain alive. Its task is to let the job dispatcher know whether this machine is currently busy running a simulation or not. When executed, it immediately registers itself with the dispatcher to join the dispatchers simulation machine farm. Later on, when its status (idle or busy) changes, it will notify the dispatcher of its new status. This enables the dispatcher to choose an available machine from its machine farm to service a job. When the coordinator receives a job from the dispatcher, it forks (executes) a simulation server to simulate the specified network and protocols. At certain times during a simulation, the coordinator may also fork (start) or kill (end) some real-life application programs, which are specified in the job to generate traffic for the simulated network. Because the coordinator has the process IDs of these forked traffic generators, the coordinator passes these process IDs into the kernel to register these traffic generators with the kernel. From now on, all time-related system calls issued by these registered traffic generators will be performed based on the virtual time of the simulated network, rather than the real time. When the simulation server is running, the coordinator communicates with the job dispatcher and the GUI program on behalf of the simulation server. For example, periodically the simulation server sends the current virtual time of the simulated network to the coordinator. The coordinator then forwards this information to the GUI program. This enables the GUI user to know the progress of the simulation. During a simulation, the user can also on-line set or get an objects value (e.g., to query or set a switchs switch table). Message exchanges happening between the simulation server and the GUI program are all done by the coordinator.

Department of CSE/ISE, AIeMS,Bangalore

Page 4

CN Lab Manual
The sixth component is the modifications that need to be made to the kernel of the simulation machine so that a simulation server can correctly run on it. For example, during a simulation, the timers of TCP connections used in the simulated network need to be triggered by the virtual time rather than by the real time. The seventh component is various protocol daemons (programs) running at the user level. Like the routing daemon routed or gated running on UNIX machines that exchange routing messages and set up system routing tables, when the NCTUns is running to simulate a network, some protocol daemons can run at the user level to perform specific jobs. For example, the real-life routed (using the RIP routing protocol) or gated (using the OSPF routing protocol) daemons can run with the NCTUns to set up the routing tables used by the routers in a simulated network. The last component is all real-life application programs running at the user level. As stated previously, any real life user-level application program can run on a simulated network to generate network traffic, configure network, or monitor network traffic, etc. For example, the tcpdump program can run on a simulated network to capture packets flowing over a link and the traceroute program can run on a simulated network to find out the routing path traversed by a packet. Note: Before executing any of the simulation program we should before the following steps : Step 1. open a terminal and execute the command

dispatcher coordinator nctnusclient

Step 2. open one more terminal and execute the command Step 3. open one more terminal and execute the command

Department of CSE/ISE, AIeMS,Bangalore

Page 5

CN Lab Manual
Program 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.

Note : Set the simulation time to 50 seconds(Menu->G-Settings->Simulation) Step 1: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another host icon as shown in the above topology. Step 2: Select the hub icon on the toolbar and drag it onto the working window. Step 3: Select the link icon on the toolbar and drag it on the screen from host (node 1) to the hub and again from host(node 2) to the hub. Here the hub acts as node 3 in the point-to-point network. This leads to the creation of the 3-node point-to-point network topology. Save this topology as a .tpl file by clicking of E(edit) button. Step 4: Double-click on host (node 1), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 20 seconds. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.2 and click OK. Double click on node editor Select FIFO and set the queue size to 50 and press OK. Select MAC, enable log statistics, select Throughput of outgoing packets.

Department of CSE/ISE, AIeMS,Bangalore

Page 6

CN Lab Manual
Step 5: Double-click on host (node 2), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 20 seconds. Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select FIFO and set the queue size to 50 and press OK. Select MAC, enable log statistics, select Throughput of incoming packets, select Number of Drop Packets and Number of Collisions Step 6: Double click on the link between node 1 and the hub to set the bandwidth to some initial value say, 10 Mbps. Repeat the same for the other node. Step 7: Click on the E(edit) button present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run simulation). No simulation settings can be changed in this mode.

Step 8: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. After the simulation is done we will find dark red line at the bottom of the screen. Step 9: To start the playback, the user can click the start icon of the time bar located at the bottom. The animation player will then start playing the recorded packet animation. Step 10: To view the results, go to the filename.results folder. Step 11: Change the bandwidth on both the link say to 5 Mbps, and run the simulation and compare the two results.

Department of CSE/ISE, AIeMS,Bangalore

Page 7

CN Lab Manual
Program 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.

Note : Set the simulation time to 50 seconds(Menu->G-Settings->Simulation) Step 1: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another two host icon as shown in the above topology. Step 2: Select the hub icon on the toolbar and drag it onto the working window. Step 3: Select the link icon on the toolbar and drag it on the screen from host (node 1- n0) to the hub and again from host(node 2- n1) to the hub and also from host (node 3-n3) to the hub. Here the hub acts as n2. Save this topology as a .tpl file by clicking of E(edit) button. Step 4: Double-click on host (node 1), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 20 seconds. Click on the Command box and type the Command according to the following syntax: stcp p 21 l 1024 1.0.1.3

Department of CSE/ISE, AIeMS,Bangalore

Page 8

CN Lab Manual
and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 5: Double-click on host (node 2), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 25 and stop time to 45 seconds. Click on the Command box and type the Command according to the following syntax: stg u 1024 20 1.0.1.3 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 6: Double-click on host (node 3), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 20 seconds. Click on the Command box and type the Command according to the following syntax: rtcp p 21 l 1024 Click on Add once again, Set start time to 25 and stop time to 45 seconds. Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of incoming packets Step 7: Click on the E(edit) button present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run simulation). Step 8: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. After the simulation is done we will find two dark red lines at the bottom of the screen. Step 9: To start the playback, the user can click the start icon of the time bar located at the bottom. The animation player will then start playing the recorded packet animation. Step 10: To view the results, go to the filename.results folder.

Department of CSE/ISE, AIeMS,Bangalore

Page 9

CN Lab Manual
Program 3: Simulate the transmission of ping messaged over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion.

Note: Set the simulation time to 500 seconds(Menu->G-Settings->Simulation) Step 1: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another 5 hosts as shown in the above topology. Step 2: Select the hub icon on the toolbar and drag it onto the working window. Connect the hosts to the hub as shown in the above topology. Step 3: Save this topology as a .tpl file by clicking of E button. Step 4. Double click on first host(node 1), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 50 seconds. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.4 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 5. Double click on second host(node 2), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 50 seconds. Click on the Command box and type the Command according to the following syntax:

Department of CSE/ISE, AIeMS,Bangalore

Page 10

CN Lab Manual
stg u 1024 50 1.0.1.4 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 6. Double click on third host(node 3), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 50 seconds. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.4 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 7: Double-click on fourth host (node 4), a host dialog box will open up. Then click on Add, another dialog box pops up. Set start time to 0 and stop time to 50 seconds.Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of incoming packets, select Number of Drop Packets and Number of Collisions Step 8: Click on the E(edit) button present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run simulation). Step 9: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. After the simulation is done we will find two dark red lines at the bottom of the screen. Step 10: While the experiment is running, open an terminal on the system and type the command on the command prompt as ping 1.0.1.4 on executing this command we can see some icmp packets being sent to the destination machine, which means that the destination machine is reachable. If the command is changed to ping 1.0.2.2 we can observe that an error message Network unreachable, which means that the destination machine is not reachable as none of the system in the above topology has an ip address 1.0.2.2 Note : With the above ping message can be tested. Next is to find the number of packets drop Step 10: To view the filename.results folder. results (no of packets dropped), go to the

Department of CSE/ISE, AIeMS,Bangalore

Page 11

CN Lab Manual
Program 4: Simulate an Ethernet LAN using N-nodes(6-10), change error rate and data rate and compare the throughput.

Note : Set the simulation time to 50 seconds(Menu->G-Settings->Simulation) Step 1: Select the switch icon on the toolbar and drag it onto the working window. Step 2: Select the hub icon on the toolbar and drag it onto the working window. Repeat the same for another hub Step 3: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another five host icon as shown in the above topology. Step 4: Save this topology as a .tpl file by clicking of E button. Step 5. Double click on first host(node 1), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.4 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets.

Department of CSE/ISE, AIeMS,Bangalore

Page 12

CN Lab Manual
Step 6: Double-click on fourth host (node 4), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of incoming packets, select Number of Drop Packets and Number of Collisions Step 7: Click on the E(edit) button present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run simulation). Step 8: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. After the simulation is done we will find two dark red lines at the bottom of the screen. Step 9: To start the playback, the user can click the start icon of the time bar located at the bottom. The animation player will then start playing the recorded packet animation. Step 10: To view the results, go to the filename.results folder. Step 11: Now change the error rate to 0.2( error rate can be changed in node editor of the receiving host(1.0.1.4) in the physical layer) but dont change the data rate (bandwidth) and note down the results. Similarly note down the result by changing the error rate to 0.2 and data rate to 5 Mbps

Department of CSE/ISE, AIeMS,Bangalore

Page 13

CN Lab Manual
Program 5: Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion window for different source / destination.

Note : Set the simulation time to 50 seconds(Menu->G-Settings->Simulation) Step 1: Select the switch icon on the toolbar and drag it onto the working window. Step 2: Select the hub icon on the toolbar and drag it onto the working window. Repeat the same for another hub Step 3: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another five host icon as shown in the above topology. Step 4: Save this topology as a .tpl file by clicking of E button. Step 5. Double click on first host(node 1), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.4 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets.

Department of CSE/ISE, AIeMS,Bangalore

Page 14

CN Lab Manual
Step 6: Double-click on fourth host (node 4), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of incoming packets, select Number of Drop Packets and Number of Collisions Step 7. Double click on second host(node 2), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.5 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 8. Double click on third host(node 3), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: stg u 1024 50 1.0.1.5 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of outgoing packets. Step 9: Double-click on fifth host (node 5), a host dialog box will open up. Then click on Add, another dialog box pops up. Click on the Command box and type the Command according to the following syntax: rtg u w log1 and click OK. Double click on node editor Select MAC, enable log statistics, select Throughput of incoming packets, select Number of Drop Packets and Number of Collisions Step 10: Click on the E(edit) button present on the toolbar in order to save the changes made to the topology. Now click on the R button (Run simulation). Step 11: Now go to Menu->Simulation->Run. Executing this command will submit the current simulation job to one available simulation server managed by the dispatcher. When the simulation server is executing, the user will see the time knot at the bottom of the screen move. The time knot reflects the current virtual time (progress) of the simulation case. After the simulation is done we will find two dark red lines at the bottom of the screen. Step 12: To start the playback, the user can click the start icon of the time bar located at the bottom. The animation player will then start playing the recorded packet animation. Step 13: To view the results, go to the filename.results folder.

Department of CSE/ISE, AIeMS,Bangalore

Page 15

CN Lab Manual
Program 6: Simulate simple ESS and with transmitting nodes in wire-less LAN by simulation and determine the performance with respect to transmission of packets.

Note : Set the simulation time to 50 seconds(Menu->G-Settings->Simulation) Step 1: Select/click the HOST icon on the toolbar and click the left mouse button on the editor, to place HOST1 on the editor. Step 2: Select/click the ROUTER icon on the toolbar and click the left mouse button on the editor, to place ROUTER1 on the editor. Step 3: Select/click the WIRELESS ACCESS POINT(802.11b) icon on the toolbar and click the left mouse button on the editor, to place ACCESS POINT 1 on the editor.Repeat this procedure and place ACCESS POINT 2 on the editor. Step 4: Select/click the MOBILE NODE (infrastructure mode) icon on the toolbar and click the left mouse button on the editor, to place MOBILE NODE 1 on the editor. Repeat this procedure and place MOBILE NODE 2, MOBILE NODE 3, MOBILE NODE 4, MOBILE NODE 5,MOBILE NODE 6,MOBILE NODE 7 and MOBILE NODE 8 on the editor. Step 5: Click on the LINK icon on the toolbar and connect ACCESS POINT1 to ROUTER1, ACCESS POINT2 to ROUTER1 and HOST to ROUTER1. Step 6: Click on the Create a moving path icon on the toolbar and draw moving path across MOBILE NODE 1,2, 3 and 4. Repeat for MOBILE NODE 5,6,7 and 8. (Accept the default speed value 10 and close the window, Click the right mouse button to terminate the path).

Department of CSE/ISE, AIeMS,Bangalore

Page 16

CN Lab Manual
Step 7: Double click on ACCESS POINT1, click Wireless Interface and enable transmission range. Repeat the same for ACCESS POINT2. To create Subnet Step 8: Have ctrl key pressed, select mobile node 1, 2, 3, 4 and access point 1 , go to N_Tools in tool bar , select 802.11(e) wireless network, select generate 802.11(e) infrastructure mobile node , a window will pop up assign subnet as 1 and gateway to 1.0.2.1( ip of router assigned to first subnet) and repeat the same for the second subnet with the subnet value as 2 and gateway value as 1.0.3.1( ip of the router assigned to second subnet). Step 9: Click on the E icon on the toolbar to save the current topology. Step 10: Double click the left mouse button while cursor is on HOST1 to open the HOST window. Select Add button on the HOST window to invoke the command window and provide the following command in the command textbox. ttcp r u s p 8001 Click OK button on the command window to exit Step 11: Repeat this step and add the following commands at HOST1 ttcp ttcp ttcp ttcp ttcp ttcp ttcp r r r r r r r u u u u u u u s s s s s s s p p p p p p p 8002 8003 8004 8005 8006 8007 8008

Step 12: Click NODE EDITOR Button on the HOST1 window and select the MAC tab from the modal window that pops up. Select LOG STATISTICS and select checkbox for Input throughput in the MAC window. Click OK button on the MAC window to exit and once again click on the OK button on the HOST window to exit. Step 13: Double click the left mouse button while cursor is on MOBILE NODE 1 to open the MOBILE NODE window. Select Application tab and select Add button to invoke the command window and provide the following command in the command textbox. ttcp t u s p 8001 1.0.1.1 (hosts ip address) Step 14: Click NODE EDITOR Button on the MOBILE NODE1 window and select the MAC tab from the nodal window that pops up. Select LOG STATISTICS and select checkbox for Output throughput in the MAC window. Click OK button on the MAC window to exit and once again click on the OK button on the MOBILE NODE1 window to exit. Step 15: Repeat the above steps (step 13 and 14) for the MOBILE NODE 2, 3, 4 ,5, 6, 7 and 8 and add the following commands at MOBILE NODE 2:- ttcp t u s p 8002 1.0.1.1 MOBILE NODE 3:- ttcp t u s p 8003 1.0.1.1

Department of CSE/ISE, AIeMS,Bangalore

Page 17

CN Lab Manual
MOBILE MOBILE MOBILE MOBILE MOBILE NODE NODE NODE NODE NODE 4:5:6:7:8:ttcp ttcp ttcp ttcp ttcp t t t t t u u u u u s s s s s p p p p p 8004 8005 8006 8007 8008 1.0.1.1 1.0.1.1 1.0.1.1 1.0.1.1 1.0.1.1

Step 16: Double click the left mouse button while cursor is on ROUTER1 to open the ROUTER window. Click NODE EDITOR Button on the ROUTER1 window and you can see three stacks. Two stacks for two ACCESS POINTS and another stack for HOST1 which is connected to the ROUTER1.Select the MAC tab of ACCESS POINT1 and Select LOG STATISTICS and select checkbox for Input throughput in the MAC window. Click OK button on the MAC window to exit. Select the MAC tab of ACCESS POINT2 and Select LOG STATISTICS and select checkbox for Input throughput in the MAC window. Click OK button on the MAC window to exit. Select the MAC tab of HOST1 and Select LOG STATISTICS and select checkbox for Output throughput in the MAC window. Click OK button on the MAC window to exit. Step 17: Simulate 1. Click R icon on the tool bar 2. Select Simulation in the menu bar and click/ select RUN in the drop down list to execute the simulation. 3. To start playback select play icon located at the bottom right corner of the editor. 4. MOBILE NODEs start moving across the paths already drawn.

Department of CSE/ISE, AIeMS,Bangalore

Page 18

CN Lab Manual

1. Write a program for error detecting code using CRC-CCITT (16bits). Program-Name: crc.c #include<stdio.h> #include<unistd.h> #include<string.h> int crc(char *input,char *output,char *gp,int flag) { int i,j; strcpy(output,input); if(flag) { for(i=1; i<strlen(gp); i++) strcat(output,"0"); } for(i=0; i<strlen(input); i++) if(*(output+i) == '1') for(j=0; j<strlen(gp); j++) { if (((*(output+i+j) =='0') && (gp[j] == '0')) || ((*(output+i+j) == '1') && (gp[j] == '1'))) *(output+i+j)='0'; else *(output+i+j)='1'; } for(i=0; i<strlen(output); i++) if(output[i] == '1') return 1; return 0; } int main() { char input[50],output[50]; char recv[50], gp[50]; system("clear"); printf("\n Enter the input message in binary\n"); scanf("%s",input); printf("\n Enter the generator polynomial\n"); Department of CSE/ISE, AIeMS,Bangalore Page 19

CN Lab Manual
scanf("%s",gp); crc(input,output,gp,1); printf("\n The transmitted message is %s %s\n",input, output+strlen (input)); printf("\n\n Enter the received message in binary \n"); scanf("%s",recv);

if(!crc(recv,output,gp,0)) printf("\n No error in data\n");

else printf("\n Error in data transmission has occurred\n");


}

Compile and run $ cc o crc crc.c $ ./crc $ Enter the input message in binary 1101011011 $ Enter the generator polynomial 10011 The transmitted message is 1101011011 1110 Enter the received message in binary 11010110111110 No error in data Enter the received message in binary 11011110111110 Error in data transmission has occurred

Department of CSE/ISE, AIeMS,Bangalore

Page 20

CN Lab Manual

2. Write a program for distance vector algorithm to find suitable path for transmission. Program-Name: dv.c #include<stdio.h> #include<string.h> struct node { int dist[20]; int from[20]; }rt[10]; int main() { int dmat[20][20]; int n,i,j,k; system("clear"); printf("Enter The Number Of Nodes\n"); scanf("%d",&n); printf("Enter The Cost Matrix\n"); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { scanf("%d",&dmat[i][j]); dmat[i][i]=0; rt[i].dist[j]=dmat[i][j]; rt[i].from[j]=j; } for(i=1;i<=n;i++) for(j=1;j<=n;j++) for(k=1;k<=n;k++) if(rt[i].dist[j]>(rt[i].dist[k]+rt[k].dist[j])) { rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j]; rt[i].from[j]=k; } for(i=1;i<=n;i++) { printf("State Value For Router %d is\n",i); Department of CSE/ISE, AIeMS,Bangalore Page 21

CN Lab Manual
for(j=1;j<=n;j++) { printf("\t\tVia %d Distance is %d",rt[i].from[j],rt[i].dist[j]); }

} return 0;

Compile and run $ cc o dv dv.c $ ./dv Enter The Number Of Nodes 3 Enter The Cost Matrix 036 709 570 State Value For Router 1 is Via 1 Distance is Via 2 Distance is Via 3 Distance is State Value For Router 2 is Via 1 Distance is Via 2 Distance is Via 3 Distance is State Value For Router 3 is Via 1 Distance is Via 2 Distance is Via 3 Distance is

0 3 6 7 0 9 5 7 0

Department of CSE/ISE, AIeMS,Bangalore

Page 22

CN Lab Manual
3. Using TCP/IP sockets, write a client server program to make the client send the file name and to make the server send back the contents of the requested file if present.

Program-Name: Client.c #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> #include<string.h> #include<stdlib.h> #define SERV_HOST_ADDR "127.0.0.1" int main(int agrc,char *argv[]) { int sockfd; struct sockaddr_in servaddr,cliaddr; char filename[10],buf[1000]; int n; servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=inet_addr(SERV_HOST_ADDR); servaddr.sin_port=htons(atoi(argv[1]); sockfd=socket(AF_INET,SOCK_STREAM,0); if(sockfd<0) { printf("Client:cant open stream socket\n"); exit(0); } else printf("Client:stream socket opened successfully\n"); if(connect(sockfd,(struct sockaddr *)&servaddr, sizeof(servaddr))<0) { Department of CSE/ISE, AIeMS,Bangalore Page 23

CN Lab Manual
printf("Client:cant connect to server\n"); exit(0); printf("Client:connected to server successfully\n");

} else

printf("\n Enter the file name to be displayed :"); scanf("%s",filename); write(sockfd,filename,strlen(filename)); printf("\n filename transferred to server\n"); n=read(sockfd,buf,1000); buf[n]=\0; printf("\n Client : Displaying file content of %s\n",filename); printf(%s,buf); close(sockfd); exit(0); } Program-Name: Server.c #include<stdio.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> #include<string.h> #include<stdlib.h> #define SERV_HOST_ADDR "127.0.0.1" int main(int agrc,char *argv[]) { int sockfd,newsockfd,clilen; struct sockaddr_in cliaddr,servaddr; char filename[10],buf[1000]; int n,fd; servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=htonl(INADDR_ANY); servaddr.sin_port=htons(atoi(argv[1]);

Department of CSE/ISE, AIeMS,Bangalore

Page 24

CN Lab Manual
sockfd=socket(AF_INET,SOCK_STREAM,0); if(sockfd<0) { printf("Server:cant open stream socket\n"); exit(0); } else printf("Server:stream socket opened successfully\n"); if((bind(sockfd,(struct sockaddr *) &servaddr,sizeof(servaddr)))<0) { printf("Server:cant bind local address\n"); exit(0); } else printf("Server:bind to local address\n"); listen(sockfd,5); printf("\n SERVER : Waiting for client...\n"); clilen=sizeof(cliaddr); newsockfd=accept(sockfd,(struct sockaddr *)&cliaddr,&clilen); if(newsockfd<0) { printf("server:accept error\n"); exit(0); } else printf("Server: accepted\n"); n=read(newsockfd,filename,10); filename[n]='\0'; printf("\n SERVER : %s is found and ready to transfer \n",filename); fd=open(filename,O_RDONLY); if(fd==-1) { write(newsockfd,File doesnt exists,25); exit(0); } n=read(fd,buf,1000); buf[n]='\0'; write(newsockfd,buf,n); Department of CSE/ISE, AIeMS,Bangalore Page 25

CN Lab Manual
printf("\n transfer success\n"); close(newsockfd); exit(0); } Compile and run - open first terminal, compile and run server there - open second terminal, compile and run client there $ cc o ser Server.c $ ./ser 8500 Server:stream socket opened successfully Server:bind to local address SERVER : Waiting for client... Server: accepted SERVER : aiems is found and ready to transfer transfer success $ cc o cli Client.c $ ./cli 8500 Client:stream socket opened successfully Client:connected to server successfully Enter the file name to be displayed : aiems filename transferred to server Client : Displaying file content of aiems Welcome to aiems computer science department. This is CN lab NOTE : If the program has to be executed on the network say on two different machines then Change the ipddress in the header file(inet.h) from 127.0.0.1 to the ipaddress of the machine(first machine), where the server program has to be typed , compiled and executed. Type the client program on the other machine(second machine) , compile it and then execute

Department of CSE/ISE, AIeMS,Bangalore

Page 26

CN Lab Manual
4. Implement the above program using as message queues or FIFOs as IPC channels. Program-Name: fclient.c #include<stdio.h> #include<fcntl.h> #include<string.h> #include<stdlib.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h> int main() { char filename[10],buf[1000]; int n,fd1,fd2; mknod("fifo1",S_IFIFO | 0666,0); mknod("fifo2",S_IFIFO | 0666,0); printf(\n Client Online \n); fd1=open("fifo1",O_WRONLY); if(fd1 == -1) { printf(\n error in opening fifo file); exit(0); } printf("\n Enter the filename...\n\n"); scanf("%s",filename); write(fd1,filename,strlen(filename)); printf("\n waiting for reply...\n"); fd2=open("fifo2",O_RDONLY); if(fd2 == -1) { printf(\n error in opening fifo file); exit(0); } n=read(fd2,buf,1000); buf[n]='\0'; printf("\n File received ..the contents are...\n"); puts(buf); close(fd1); close(fd2); unlink("fifo1"); unlink("fifo2"); Department of CSE/ISE, AIeMS,Bangalore Page 27

CN Lab Manual
exit(0); } Program-Name: fserver.c #include<stdio.h> #include<fcntl.h> #include<stdlib.h> #include<string.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h> int main() { char filename[10],buf[1000]; int n,fd1,fd2,fd; mknod("fifo1",S_IFIFO | 0666,0); mknod("fifo2",S_IFIFO | 0666,0); printf("\n Server Online\n"); fd1=open("fifo1",O_RDONLY); if(fd1 == -1) { printf(\n error in opening fifo file); exit(0); } n = read(fd1,filename,10); filename[n]='\0'; fd2=open("fifo2",O_WRONLY); if(fd2 == -1) { printf(\n error in opening fifo file); exit(0); } fd=open(filename,O_RDONLY); if(fd==-1) { write(fd2,File doesnt exists,25); unlink("fifo1"); unlink("fifo2"); close(fd1); close(fd2); close(fd); Department of CSE/ISE, AIeMS,Bangalore Page 28

CN Lab Manual
exit(0); } n=read(fd,buf,1000); buf[n]='\0'; write(fd2,buf,n); printf("\n SERVER :Transfer completed\n"); unlink("fifo1"); unlink("fifo2"); close(fd1); close(fd2); clode(fd); exit(0); }

Compile and run - open first terminal, compile and run server there - open second terminal, compile and run client there $ cc o ser fserver.c $ ./ser Server Online Sever: aiems is found! transferring the contents SERVER :Transfer completed $ cc o cli fclient.c $ ./cli CLient Online! CLIENT : enter the filename... aiems File received ..the contents are... Welcome to aiems computer science department. This is CN lab

Department of CSE/ISE, AIeMS,Bangalore

Page 29

CN Lab Manual
5. Write a program for simple RSA algorithm to encrypt and decrypt the data. Program-Name : rsa.c #include<math.h> #include<stdlib.h> #include<stdio.h> long gcd(long a,long b) { long r; while(b!=0) { r=a%b; a=b; b=r; } return a; } int main() { char long long long

message[100]; p,q,n,phi,i,e=0,d=0; nummes[100]={0}; encrypted[100]={0},decrypted[100]={0};

printf("Enter The Message To Be Encrypted\n"); gets(message); printf("\nenter value of p and q\n"); scanf("%ld%ld",&p,&q); n=p*q; phi=(p-1)*(q-1); for(i=2;i<phi;i++) if(gcd(i,phi)==1) break; e=i; for(i=2;i<phi;i++) if(((e*i)%phi)==1)break; d=i; Department of CSE/ISE, AIeMS,Bangalore Page 30

CN Lab Manual
for(i=0;i<strlen(message);i++) nummes[i]=message[i]; for(i=0;i< strlen(message);i++) { encrypted[i]=1; for(j=0;j<e;j++) encrypted[i] = (encrypted[i]*nummes[i])%n; } printf("\n Encrypted message\n"); for(i=0;i< strlen(message);i++) printf(" %ld ",encrypted[i]); for(i=0;i< strlen(message);i++) { decrypted[i]=1; for(j=0;j<d;j++) decrypted[i]=(decrypted[i]*encrypted[i])%n; } printf("\n Decrypted message\n "); for(i=0;i< strlen(message);i++) printf("%c",(char)(decrypted[i])); return 0; } Compile and run $ cc o rsa rsa.c $ ./rsa Enter The Message To Be Encrypted aiems bangalore enter value of p and q 37 71 Encrypted message 1914 1981 2560 1670 1602 1138 1981 76 Decrypted message aiems Bangalore

Department of CSE/ISE, AIeMS,Bangalore

Page 31

CN Lab Manual
6. Write a program for congestion control using leaky bucket algorithm.

Program-Name :Congestion.c #include<stdio.h> #include<string.h> int minimum(int x,int y) { if(x<y) return x; else return y; } int main() { int nsec,bsize,oprate,i,drop=0,min,count=0,input[25]; system("clear"); printf("Enter The No. Of Seconds You Want To Stimulate\n"); scanf("%d",&nsec); printf("Enter The Bucket Size\n"); scanf("%d",&bsize); printf("Enter The Processing Rate\n"); scanf("%d",&oprate); for(i=0;i<nsec;i++) { printf("Enter The Size Of The Packet Entering At %d sec\n",i+1); scanf("%d",&input[i]); } printf("\nSecond|Packet Recieved|Packet Sent|PacketLeft|Packet Dropped|\n"); printf("--------------------------------------------------------------\n"); for(i=0;i<nsec;i++) { count=count + input[i]; if(count>bsize) { Department of CSE/ISE, AIeMS,Bangalore Page 32

CN Lab Manual
drop=count-bsize; count=bsize;

} printf("%d\t",i+1); printf("%d\t\t",inp[i]); min=minimum(count,process); printf("%d\t\t",min); count=count-min; printf("%d\t\t",count); printf("%d\n",drop); drop=0; } for(;count!=0;i++) { printf("%d\t",i+1); printf("0\t\t"); min=minimum(count,process); printf("%d\t\t",min); count=count-mini; printf("%d\t\t",count); printf("%d\n",drop); } } Compile and run $ cc o Congestion Congestion.c $ ./Congestion Enter 5 Enter 2 Enter 3 Enter 5 Enter 4 Enter 3 The Bucket Size The Processing Rate The No. Of Seconds You Want To Stimulate The Size Of The Packet Entering At 1 sec The Size Of The Packet Entering At 1 sec The Size Of The Packet Entering At 1 sec

Department of CSE/ISE, AIeMS,Bangalore

Page 33

CN Lab Manual
Second|Packet Recieved|Packet Sent|PacketLeft|Packet Dropped| ---------------------------------------------------------------------------1 5 2 3 0 2 4 2 3 2 3 3 2 3 1 4 0 2 1 0 5 0 1 0 0

Department of CSE/ISE, AIeMS,Bangalore

Page 34

You might also like