untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · web...

74
REVA ITM Dept of Information Science & Engg INTRODUCTION Network simulation is an important tool in developing, testing and evaluating network protocols. Simulation can be used without the target physical hardware, making it economical and practical for almost any scale of network topology and setup. It is possible to simulate a link of any bandwidth and delay, even if such a link is currently impossible in the real world. With simulation, it is possible to set each simulated node to use any desired software. This means that meaning deploying software is not an issue. Results are also easier to obtain and analyze, because extracting information from important points in the simulated network is as done by simply parsing the generated trace files. Simulation is only of use if the results are accurate, an inaccurate simulator is not useful at all. Most network simulators use abstractions of network protocols, rather than the real thing, making their results less convincing. S.Y. Wang reports that the simulator OPNET uses a simplified finite state machine to model complex TCP protocol processing. [19] NS-2 uses a model based on BSD TCP, it is implemented as a set of classes using inheritance. Neither uses protocol code that is used in real world networking. Improving Network Simulation: Wang states that “Simulation results are not as convincing as those produced by real hardware and software equipment.” This statement is followed by an explanation of the fact that most existing network simulators can only simulate real life network protocol implementations with limited detail, which can lead to incorrect results. Another paper includes a similar statement, “running the actual TCP code is preferred to running an abstract specification of the protocol.” Brakmo and Peterson go on to discuss how the BSD implementations of TCP are quite important with respect to timers. Simulators often use more accurate round trip time measurements than those used in the BSD implementation, making results differ. Using real world network stacks in a simulator should make results more accurate, but it is not clear how such stacks should be System Software Lab Manual 1 / 74

Upload: others

Post on 14-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

INTRODUCTION

Network simulation is an important tool in developing, testing and evaluating network protocols. Simulation can be used without the target physical hardware, making it economical and practical for almost any scale of network topology and setup. It is possible to simulate a link of any bandwidth and delay, even if such a link is currently impossible in the real world. With simulation, it is possible to set each simulated node to use any desired software. This means that meaning deploying software is not an issue. Results are also easier to obtain and analyze, because extracting information from important points in the simulated network is as done by simply parsing the generated trace files.

Simulation is only of use if the results are accurate, an inaccurate simulator is not useful at all. Most network simulators use abstractions of network protocols, rather than the real thing, making their results less convincing. S.Y. Wang reports that the simulator OPNET uses a simplified finite state machine to model complex TCP protocol processing. [19] NS-2 uses a model based on BSD TCP, it is implemented as a set of classes using inheritance. Neither uses protocol code that is used in real world networking.

Improving Network Simulation:

Wang states that “Simulation results are not as convincing as those produced by real hardware and software equipment.” This statement is followed by an explanation of the fact that most existing network simulators can only simulate real life network protocol implementations with limited detail, which can lead to incorrect results. Another paper includes a similar statement, “running the actual TCP code is preferred to running an abstract specification of the protocol.” Brakmo and Peterson go on to discuss how the BSD implementations of TCP are quite important with respect to timers. Simulators often use more accurate round trip time measurements than those used in the BSD implementation, making results differ.

Using real world network stacks in a simulator should make results more accurate, but it is not clear how such stacks should be integrated with a simulator. The network simulator NCTUns shows how it is possible to use the network stack of the simulators machine.

Network Simulation Experience

The Network Simulator offers a simplified and complete network simulation experience. The following diagram depicts this functionality offered by the Network Simulator.

System Software Lab Manual 1 / 55

Page 2: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

The Network Simulator can design and simulate a network with SNMP, TL1, TFTF, FTP, Telnet and IOS devices, in four simple steps:

1. Add devices to the Device tree: Add devices with the required configuration to the device tree in the Network Designer. Preconfigured devices are also bundled with the toolkit.

2. Create the Network: Create and add bulk devices to the network, at one shot.

3. Configure the Network devices: Configure the devices in the network, if required.

3. Start the Network: Start the network or start individual agents in the network. The MIB Browser and TL1 Craft Interface test tools, can be used as the manager tools for testing.

Network Emulation

Network emulation refers to actual network traffic passing through some software which might do some analysis or perhaps modify the traffic in some way. The Emulation Network in the WAND group is used for testing and evaluation of networking software and hardware. The scale is limited; it is made up 24 emulation machines and one central controlling computer. Setup of such a network is time consuming and expensive: in addition to the aforementioned 25 computers, a Cisco 2950 switch and a Cyclades 32 port terminal server are included in the network. Each emulation machine also has a 4 port network interface controller. The controlling machine includes special capture cards (known as DAG [6] cards) to allow easier capture and processing of network traffic. This network has no easy way of adding latency and bandwidth bottlenecks, which means creating adverse conditions on the network is difficult. It is possible to use Dummy net to add latency, but this is a lot of work. There is a project to solve this issue; a non blocking crossbar Ethernet switch is being created for the network, but the cost involved is large.

Other network emulation done in the WAND group include validating the WAND simulator. This was done by setting up a physical network with FreeBSD machines using Dummynet to add latency. Dummy net is one example of network emulation software, NIST Net is another, it claims to “allow controlled, reproducible experiments with network performance sensitive/adaptive applications and control protocols in a simple laboratory setting”.

NS-2 also provides some network emulation functionality, it is able to capture packets

System Software Lab Manual 2 / 55

Page 3: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

from the live network and drop, delay, re-order, or duplicate them. Emulation, especially in the case of a network simulator like NS-2, is interesting because it is using real world data from real world network stacks. Emulation offers something simulation never can: it is performed on a real network, using actual equipment and real software. However, it is very limited compared to simulation in other areas; for example scale. The WAND Emulation Network described earlier requires a lot of setup and is expensive, yet only contains 24 emulation machines. There is no theoretical limit to the number of nodes a simulator can handle, and increasing the size of a simulation does not cost anything. The factors to consider are RAM, disk space and the small amount of time taken to change a simulation script. In general, changing the simulation is a simple step, though it would be complex in the case a huge amount of nodes being required (a million, for example).

Also, network emulation must of course be run in real time, where simulation can sometimes simulate large time periods in a small amount of time. In the case of a million nodes, the simulation might run in greater than real time because the hardware it is run on would limit performance.

Introduction to Network SimulatorsNetwork simulators implemented in software are valuable tools for researchers to develop, test,

and diagnose network protocols. Simulation is economical because it cancarry out experiments without the actual hardware. It is flexible because it can, for example, simulate a link with any bandwidth and propagation delay. Simulation resultsare 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 network simulators usually can only simulate real-life network protocol implementations with limited details, and this may lead to incorrect results.

• These simulators are not extensible in the sense that they lack the standard UNIX POSIX application programming interface (API). As such, existing or to-be-developed real-life application programs cannot run normally to generate traffic for a simulated network. Instead, they must be rewritten to use the internal API provided by the simulator (if there is any) and be compiled with the simulator to form a single, big, and complex program.

To overcome these problems, Wang invented a kernel re-entering simulation methodology and used it to implement the Harvard network simulator. Later on, Wang further improved the methodology and used it to design and implement the NCTUns network simulator and emulator.

System Software Lab Manual 3 / 55

Page 4: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

Different types of simulatorsSome of the different types of simulators are as follows:-

1 MIT's NETSIM 2. NIST 3. CPSIM 4. INSANE 5. NEST 6. REAL 7. NS 8. OPNET 9.NCTUns

NCTUns

IntroductionNCTUns is open source, high quality, and supports many types of networks.The NCTUns

is a high-fidelity and extensible network simulator and emulator capable of simulating various protocols used in both wired and wireless IP networks. Its core technology is based on the novel kernel re-entering methodology invented by Prof. S.Y. Wang [1, 2] when he was pursuing his Ph.D. degree at Harvard University. Due to this novel methodology, NCTUns provides many unique advantages that cannot be easily achieved by traditional network simulators such as ns-2 [3] and OPNET [4].

After obtaining his Ph.D. degree from Harvard University in September 1999, Prof. S.Y. Wang returned to Taiwan and became an assistant professor in the Department of Computer Science and Information Engineering, National Chiao Tung University (NCTU), Taiwan, where he founded his “Network and System Laboratory.” Since that time, Prof. S.Y. Wang has been leading and working with his students to design and implement NCTUns (the NCTU Network Simulator) for more than five years.

Salient features of NCTUns The NCTUns network simulator and emulator has many useful features listed as follows:

● It can be used as an emulator. An external host in the real world can exchange packets (e.g., set up a TCP connection) with nodes (e.g., host, router, or mobile station) in a network simulated by NCTUns. Two external hosts in the real world can also exchange their packets via a network simulated by NCTUns. This feature is very useful as the function and performance of real-world devices can be tested under various simulated network conditions.

● It directly uses the real-life Linux ’s TCP/IP protocol stack to generate high-fidelity simulation results. By using a novel kernel re-entering simulation methodology, a real-life UNIX (e.g., Linux) kernel’s protocol stack can be directly used to generate high-fidelity simulation results.

● It can use any real-life existing or to-be-developed UNIX application program as a traffic generator program without any modification. Any real-life program can be run on a simulated network to generate network traffic. This enables a researcher to test the functionality and performance of a distributed application or system under various network conditions. Another important advantage of this feature is that application programs developed during simulation studies can be directly moved to and used on real-world UNIX machines after simulation studies are finished. This eliminates the time and effort required to port a simulation prototype to a real-world implementation if traditional network simulators are used.

● It can use any real-life UNIX network configuration and monitoring tools. For example, the UNIX route, ifconfig, netstat, tcpdump, traceroute commands can be run on a simulated network to

System Software Lab Manual 4 / 55

Page 5: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

configure or monitor the simulated network. ● In NCTUns, the setup and usage of a simulated network and application programs are exactly the

same as those used in real-world IP networks. For example, each layer-3 interface has an IP address assigned to it and application programs directly use these IP addresses to communicate with each other. For this reason, any person who is familiar with real-world IP networks can easily learn and operate NCTUns in a few minutes. For the same reason, NCTUns can be used as an educational tool to teach students how to configure and operate a real-world network.

● It can simulate fixed Internet, Wireless LANs, mobile ad hoc (sensor) networks, GPRS networks, and optical networks. A wired network is composed of fixed nodes and point-to-point links. Traditional circuit-switching optical networks and more advanced Optical Burst Switching (OBS) networks are also supported. A wireless networks is composed of IEEE 802.11 (b) mobile nodes and access points (both the ad-hoc mode and infra-structure mode are supported). GPRS cellular networks are also supported.

● It can simulate various networking devices. For example, Ethernet hubs, switches, routers, hosts, IEEE 802.11 (b) wireless stations and access points, WAN (for purposely delaying/dropping/reordering packets), Wall (wireless signal obstacle), GPRS base station, GPRS phone, GPRS GGSN, GPRS SGSN, optical circuit switch, optical burst switch, QoS DiffServ interior and boundary routers, etc.

● It can simulate various protocols. For example, IEEE 802.3 CSMA/CD MAC, IEEE 802.11 (b) CSMA/CA MAC, learning bridge protocol, spanning tree protocol, IP, Mobile IP, Diffserv (QoS), RIP, OSPF, UDP, TCP, RTP/RTCP/SDP, HTTP, FTP, Telnet, etc.

● Its simulation speed is high. By combining the kernel re-entering methodology with the discrete-event simulation methodology, a simulation job can be finished quickly.

● Its simulation results are repeatable. If the chosen random number seed for a simulation case is fixed, the simulation results of a case are the same across different simulation runs even though there are some other activities (e.g., disk I/O) occurring on the simulation machine.

● It provides a highly integrated and professional GUI environment. This GUI can help a user (1) draw network topologies, (2) configure the protocol modules used inside a node, (3) specify the moving paths of mobile nodes, (4) plot network performance graphs, (5) playing back the animation of a logged packet transfer trace, etc. All these operations can be easily and intuitively done with the GUI.

● Its simulation engine adopts an open-system architecture and is open source. By using a set of module APIs provided by the simulation engine, a protocol module writer can easily implement his (her) protocol and integrate it into the simulation engine. NCTUns uses a simple but effective syntax to describe the settings and configurations of a simulation job. These descriptions are generated by the GUI and stored in a suite of files. Normally the GUI will automatically transfer these files to the simulation engine for execution. However, if a researcher wants to try his (her) novel device or network configurations that the current GUI does not support, he (she) can totally bypass the GUI and generate the suite of description files by himself (herself) using any text editor (or script program). The non-GUI-generated suite of files can then be manually fed to the simulation engine for execution.

System Software Lab Manual 5 / 55

Page 6: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

● It supports remote and concurrent simulations. NCTUns adopts a distributed architecture. The GUI and simulation engine are separately implemented and use the client-server model to communicate. Therefore, a remote user using the GUI program can remotely submit his (her) simulation job to a server running the simulation engine. The server will run the submitted simulation job and later return the results back to the remote GUI program for analyzes. This scheme can easily support the cluster-computing model in which multiple simulation jobs are performed in parallel on different server machines. This can increase the total simulation throughput.

● It supports more realistic wireless signal propagation models. In addition to providing the simple (transmission range = 250 m, interference range = 550 m) model that is commonly used in the ns-2, NCTUns provides a more realistic model in which a received bit’s BER is calculated based on the used modulation scheme, the bit’s received power level, and the noise power level around the receiver. Large-scale path loss and small-scale fading effects are also simulated.

GETTING STARTED

Setting up the environment

A user using the NCTUns in single machine mode, needs to do the following steps before he/she starts the GUI program:

1. Start up the dispatcher on terminal 1.

2. Start up the coordinator on terminal 2.

3. Start up the nctunsclient on terminal 3.

After the above steps are followed, the starting screen of NCTUns disappears and the user is presented with the working window.

PART-A

System Software Lab Manual 6 / 55

Page 7: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

1. Simulate a three-node point-to-point network with a duplex link between them. Set the queue size and vary the bandwidth and find the number of packets dropped.

STEPS:Step1: Create a topology as shown in the below figure.

Step 2: Select the hub icon on the toolbar and drag it onto the working window.

Step 3: Select the host icon on the toolbar and drag it onto the working window. Repeat this for another host icon.

Step 4: Select the link icon on the toolbar and drag it on the screen from host (node 1) to the hub andagain 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.

Step 5:Double-click on host(node 1), a host dialog box will open up. Click on Node editor and you cansee the different layers- interface, ARP,FIFO, MAC, TCPDUMP, Physical layers. Select MACand then select full-duplex for switches and routers and half duplex for hubs, and in logStatistics, select Number of Drop Packets, Number of Collisions, Throughput of incomingpackets and Throughput of outgoing packets. Then click on Add. Another dialog box pops up.Click on the Command box and type the following Command.

stcp –p 3000 –l 1024 1.0.1.2 click ok.Here, 1.0.1.2 is IP address of the host 2 (Node 2), and 3000 is the port No.

Step 6: Double-click on host (node 2), and follow the same step as above with only change in commandaccording to the following syntax:

rtcp –p 3000 –l 1024 and click OK.Step 7: Click on the E button (Edit Property) present on the toolbar in order to save the changes made to

the topology. Now click on the R button (Run Simulation). By doing so a user can run/pause/continue/stop/abort/disconnect/reconnect/submit a simulation. No simulation

settingscan be changed in this mode.

System Software Lab Manual 7 / 55

Page 8: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

Step 8: Now go to Menu->Simulation->Run. Executing this command will submit the currentSimulation job to one available simulation server managed by the dispatcher. When thesimulation 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.

Step 9: After the simulation is completed, click on the play button and mean while plot the graphs of thedrop packets and through put input and through put output. These log files are created infilename.results folder.

Step 10. Now click on the link (connecting the hub and host2) and change the bandwidth say, 9 Mbps, and run the simulation and compare the two results.

Graphs Sheet:

EXAMPLE AND RESULTS OF EXPT 1By using HUB:

Commands used: stcp –p 3000 –l 1024 1.0.1.2 Rtcp –p 3000 –l 1024

By setting the bandwidth as 10 Mbps on both the links and queue size as 50 we obtain the following results:

Output throughput (host 1) = 1177

Input throughput (host 2) = 1177

Collision and drop = 0

By changing bandwidth to 9Mbps in the destination link, we obtain the following results:

Output throughput (host 1) =1177

Input throughput (host 2) = 0 - 77 Collision and drop = 1100

Note: The results of the experiments vary from simulation to simulation.

System Software Lab Manual 8 / 55

Page 9: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

By using SWITCH

Commands used: stcp -p 7000 -l 1024 1.0.1.2 rtcp -p 7000 -l 1024

Results: By setting the bandwidth as 10 Mbps on both the links and queue size as 50 we obtain the following results:

output throughput (host 1) = 1190

input throughput host 2 ) = 1190 collision and drop = 0

By changing bandwidth to 9Mbps in the destination link, we obtain the following results: output throughput (host 1) =1190

input throughput (host 2) = varying

collision and drop = 0 - 7

2. Simulate a four-node point-to-point network and connect the link as follows: Apply a TCP agent between n0 to n3 and apply a UDP agent between n1 and n3. Apply relevant applications over TCP and UDP agents changing the parameters and determine the number of packets sent by two agents.

STEPS:Step1: Create a topology as shown in the below figure.

Step 2: Select 3 Nodes (1,2,3) and connect them using a hub(4) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Double click on host (Node 1) and goto node editor, and click on MAC 8023 and put a check

on the Throughput of Outgoing Packets. Click ok. Then click on ADD and type the following command.

stcp –p 3000 –l 1024 1.0.1.3 and click OKHere 1.0.1.3 is the IP address of the Host 3 (Receiver) and 3000 is the port no.

System Software Lab Manual 9 / 55

Page 10: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

Step 4 b : Double-click on host (node 2), and follow the same step as above with only change in command according to the following syntax:

stg –u 1024 100 1.0.1.3 and click OK

Here, 1.0.1.3 is Receiver IP and 100 is the bandwidth. This forms the UDP connection. Step 5: Double-click on host (node 3), and follow the same step as above and check on Throughput of

Incoming Packets. And type the following commands:rtcp –p 3000 –l 1024 click ok ( for TCP)rtg –u –w log1 click ok ( for UDP)

Here, w is bandwidth and log1 is the name of the file.

Step 6: Click R Button and then goto Menu->Simulation->Run. Step 7: After the simulation is completed, click on the play button and mean while plot the graphs of the

Throughput Input and Throughput Output. These log files are created in filename.results folder. Graphs Sheet:

EXAMPLE AND RESULTS OF EXPT 2Commands used:

stcp -p 3000 -l 1024 1.0.1.3 (for TCP)stg -u 1024 100 1.0.1.3 (for UDP)

rtcp -p 3000 -l 1024 (for TCP)rtg -u -w log1 (for UDP)

Results: By setting the bandwidth as 100 Mbps on the TCP link and queue size as 50 we obtain the following results:

Average no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets sent = 1180

Note: The result varies based on the bandwidth.

System Software Lab Manual 10 / 55

Page 11: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

3. Simulate the different types of Internet traffic such as FTP, TELNET over a network and Analyze the throughput.

STEPS :Step1: Create a topology as shown in the below figure.

Step 2: Select 3 Nodes (1,2,3) and connect them using a hub(4) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Double click on host (Node 1) and goto node editor, and click on MAC 8023 and put a check

on the Throughput of Outgoing Packets. Click ok. Then click on add and type the followingcommand.

stcp –p 21 –l 1024 1.0.1.3 and click OK

Here 1.0.1.3 is the IP address of the Host 3 (Receiver) and 21 is the FTP port no.Step 4 b : Double-click on host (node 2), and follow the same step as above with only change in

command according to the following syntax:

stcp –p 23 –l 1024 1.0.1.3 and click OK

Here 1.0.1.3 is the IP address of the Host 3 (Receiver) and 21 is the TELNET port no.Step 5: Double-click on host (node 3), and follow the same step as above and check on Throughput of

Incoming Packets. And type the following commands :rtcp –p 21 –l 1024 click ok ( for FTP)rtcp –p 23 –l 1024 click ok ( for TELNET)

Step 6: Click on R Button and then goto Menu->Simulation->Run. Step 7: After the simulation is completed, click on the play button and mean while plot the graphs of the

Throughput Input and Throughput Output. These log files are created in filename.results folder.

EXAMPLE AND RESULTS OF EXPT 3Result:

Command used: stcp -p 21 -l 1024 1.0.1.3 (For FTP) stcp -p 23 -l 1024 1.0.1.3 (For TELNET)

rtcp -p 21 -l 1024 (For FTP) rtcp -p 23 -l 1024 (For TELNET)

System Software Lab Manual 11 / 55

Page 12: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

Graphs Sheet:

For FTP:

Output Throughput (Host1) = 680-1097

Input Throughput (Host3) = 680-1097

For TELNET:

Output Throughput (Host2)= 495-1095

Input Throughput (Host3)= 495-1095

4. Simulate the transmission of ping messages over a network topology consisting of 6 nodes and find the number of packets dropped due to congestion.

STEPS:Step1: Create a topology as shown in the below figure.

Step 2: Select 6 Nodes (1-6) and connect them using a hub(7) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Let us say, Node1 and node 6 are source and destination. Double click on host (Node 1) and

System Software Lab Manual 12 / 55

Page 13: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

goto node editor, and click on MAC 8023 and put a check on the Collision and packets dropped. Click ok. Then click on ADD and type the following command.

stcp –p 3000 –l 1024 1.0.1.6 click ok.Here 1.0.1.6 is the IP address of the Host 6 (Receiver) and 3000 is the port no.

Step 4 b : Double-click on host (node 6 ), and follow the same step as above and type the followingcommands:

rtcp –p 3000 –l 1024 and click OK

Step 5: Click on R Button and then goto Menu->Simulation->Run. Step 6: Now click on the host (Node1) and click on command console and ping the destination node by

typing the following command : ping 1.0.1.6 where 1.0.1.6 is the IP address of Host 6. After doing so, the ping command gets executed. As shown in the below figure.

Step 7: After the simulation is completed, click on the play button and mean while plot the graphs of theCollision and packets dropped.. These log files are created in filename.results folder.

Graphs Sheet:

System Software Lab Manual 13 / 55

Page 14: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

4. Simulate an Ethernet LAN using N nodes (6-10), change error rate and data rate and compare throughput.

STEPS:Step1: Create a topology as shown in the below figure.

Step 2: Select 6 Nodes (1-6) and connect them using a hub(7) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Let us say, Node1 and node 6 are source and destination. Double click on host (Node 1) and

goto node editor, and click on MAC 8023 and put a check on the Throughput of OutgoingPackets. Click ok. Then click on ADD and type the following command.

stcp –p 3000 –l 1024 1.0.1.6

Here 1.0.1.6 is the IP address of the Host 6 (Receiver) and 3000 is the port no.Step 4 b : Double-click on host (node 6 ), and follow the same step as above and check on Throughput

Of Incoming Packets. And type the following commands: rtcp –p 3000 –l 1024 Step 5: Click on R Button and then goto Menu->Simulation->Run. Step 6: After the simulation is completed, click on the play button and mean while plot the graphs of the

Throughput Input and Throughput Output. These log files are created in filename.resultsfolder.

Step 7: Change error rate and data rate in Physical layer and then run the simulation again and comparethe Throughput Input and Throughput Output of 1st and 2nd reading.

Graphs Sheet:

System Software Lab Manual 14 / 55

Page 15: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

EXAMPLE AND RESULTS OF EXPT 5

Results:Commands: stcp -p 3000 -l 1024 1.0.1.6 rtcp -p 3000 -l 1024

Initial error rate: 0.0

Initial data rate: 10 Mbps

Output Throughput: 654-1091

Input Throughput: 654-1091

Changed error rate: 1.0

Changed data rate: 10 Mbps

Output Throughput: 654-1091

Input Throughput: 654-1091

Error rate: 1.0

Data rate: 100 Mbps

Output Throughput: 1547-9765Input Throughput: 1547-9765

System Software Lab Manual 15 / 55

Page 16: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

5. Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and determine collisions across different nodes.

STEPS :Step1: Create a topology as shown in the below figure.

Step 2: Select 6 Nodes (1-6) and connect them using a hub(7) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Let us say, Node1 and node 6 are source and destination. Double click on host (Node 1) and

goto node editor, and click on MAC 8023 and put a check on the Collision and Packets Dropped. Click ok. Then click on ADD and type the following command.

stcp –p 3000 –l 1024 1.0.1.6

Here 1.0.1.6 is the IP address of the Host 6 (Receiver) and 3000 is the port no.Step 4 b : Double-click on host (node 6 ), and follow the same step as above And type the following

commands: rtcp –p 3000 –l 1024

Step 5: Click on R Button and then goto Menu->Simulation->Run. Step 6: After the simulation is completed, click on the play button and mean while plot the graphs of the

Collision and packets Dropped. These log files are created in filename.results folder.

Graphs Sheet:

System Software Lab Manual 16 / 55

Page 17: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

EXAMPLE AND RESULTS OF EXPT 6Results:Commands: stcp -p 3000 -l 1024 1.0.1.6 rtcp -p 300 -l 1024

Drops at node 1 : 324-750Drops at node 6 : 274-930

7. Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination.STEPS:Step1: Create a topology as shown in the below figure.

Step 2: Select 6 Nodes (1-6) and connect them using a hub(7) as shown in above. Step 3: Go to edit mode and save the topology.Step 4 a : Let us say, Node1 and node 6 are source and destination. Double click on host (Node 1) and

goto node editor, and click on MAC 8023 and put a check on the Collision and Packets Dropped. Click ok. Then click on ADD and type the following command.

stcp –p 3000 –l 1024 1.0.1.6Here 1.0.1.6 is the IP address of the Host 6 (Receiver) and 3000 is the port no.

Step 4 b : Double-click on host (node 6 ), and follow the same step as above And type the followingcommands: rtcp –p 3000 –l 1024

Step 5: Click on R Button and then goto Menu->Simulation->Run. Step 6: After the simulation is completed, click on the play button and mean while plot the graphs of the

Collision and packets Dropped. These log files are created in filename.results folder.

EXAMPLE AND RESULTS OF EXPT 7Results:Commands: stcp -p 300 -l 1024 1.0.1.6 rtcp -p 300 -l 1024

Drops at node 1: 324-750. Drops at node 6: 274-930.Note: The only difference between the 6th experiment and the present experiment is that here we need to plot the congestion window i.e. collision log.

System Software Lab Manual 17 / 55

Page 18: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

8. Simulate simple BSS and with transmitting nodes in wireless LAN by simulation and determine the performance with respect to transmission of packets.

STEPS:

Step 1: Connect a host and two WLAN access points to a router.

Step 2: Setup multiple mobile nodes around the two WLAN access points and set the path for each mobile node.

Step 3: Setup a ttcp connection between the mobile nodes and host using the following command:

ttcp -r -u -s [-p port number]

Step 4: Setup the input throughput log at the destination host.

Step 5: To set the transmission range go to Menu->Settings->WLAN mobile node->Show transmission range.

Step 5:View the results in the filename. results.

The screenshot of the topology is shown below:

EXAMPLE AND RESULTS OF EXPT 8Results:

Command: ttcp -r -u -s -p 7000Output Throughput : 1190

PART-B

System Software Lab Manual 18 / 55

Page 19: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

1. Write a program for error detecting code using CRC-CCITT (16-bits).

ERROR DETECTING CODE USING CRC-CCITT

Overview:The accurate implementations (long-hand and programmed) of the 16-bit CRC-CCITT

specification, is as follows: ● Width = 16 bits ● Truncated polynomial = 0x1021 ● Initial value = 0xFFFF ● Input data is NOT reflected ● Output CRC is NOT reflected ● No XOR is performed on the output CRC

Theoretical Concepts: Important features of a standard CRC are that it:

● Can be used to validate data ● Is reproducible by others

The first feature above is easy to realize in a closed system if corruption of data is infrequent (but substantial when it occurs). The term "closed system" refers to a situation where the CRC need not be communicated to others. A correct implementation of a 16-bit CRC will detect a change in a single bit in a message of over 8000 bytes. An erroneous CRC implementation may not be able to detect such subtle errors. If errors are usually both rare and large (affecting several bits), then a faulty 16-bit CRC implementation may still be adequate in a closed system. The second feature above -- that the CRC is reproducible by others -- is crucial in an open system; that is, when the CRC must be communicated to others. If the integrity of data passed between two applications is to be verified using a CRC defined by a particular standard, then the implementation of that standard must produce the same result in both applications -- otherwise, valid data will be reported as corrupt. Reproducibility may be satisfied by even a botched implementation of a standard CRC in most cases -- if everyone uses the same erroneous implementation of the standard. But this approach:

● Modifies the standard in ways that are both unofficial and undocumented. ● Creates confusion when communicating with others who have not adopted the botched

implementation as the implied standard.

The CRC value for the 9-byte reference string, "123456789" is 0xE5CC.The need to focus on the 16-bit CRC-CCITT (polynomial 0x1021) and not CRC16 (polynomial 0x8005),are as follows :

● Is a straightforward 16-bit CRC implementation in that it doesn't involve: ● reflection of data ● reflection of the final CRC value

● Starts with a non-zero initial value -- leading zero bits can't affect the CRC16 used by LHA, ARC, etc., because its initial value is zero.

● It requires no additional XOR operation after everything else is done. The CRC32 implementation used by Ethernet, Pkzip, etc., requires this operation; less common 16-bit CRCs

System Software Lab Manual 19 / 55

Page 20: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

may require it as well.

The need to use a 16-bit CRC instead of a 32-bit CRC is as follows : ● Can be calculated faster than a 32-bit CRC. ● Requires less space than a 32-bit CRC for storage, display or printing. ● Is usually long enough if the data being safeguarded is fewer than several thousand bytes in

length, e.g., individual records in a database.

Example:-Calculation of the 16-bit CRC-CCITT for a one-byte message consisting of the letter "A": Quotient= 111100001110111101011001 poly= ------------------------------------------ 10001000000100001 ) 1111111111111111010000010000000000000000 10001000000100001 --------------------------- red bits are initial value 11101111110111111 bold bits are message 10001000000100001 blue bits are augmentation -------------------------- 11001111100111100 10001000000100001 ------------------------------- 10001111000111010 10001000000100001 ---------------- ----------------- 00001110000110110 00000000000000000 -------------------------------- 00011100001101100 00000000000000000 ------------------------------------- 00111000011011000 00000000000000000 ------------------------------------- 01110000110110001 00000000000000000 ------------------------------------ 11100001101100010 10001000000100001 ----------------------------------- 11010011010000110 10001000000100001 ----------------------------------- 10110110101001110

PROGRAM :

System Software Lab Manual 20 / 55

Page 21: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

#include<stdio.h>#include<string.h>char data[100],concatdata[117],src_crc[17],dest_crc[17],frame[120],divident[18],divisor[18]="10001000000100001",res[17]="0000000000000000";

void crc_cal(int node){

int i,j;for(j=17;j<=strlen(concatdata);j++){

if(divident[0]=='1'){

for(i=1;i<=16;i++)if(divident[i]!=divisor[i])

divident[i-1]='1';elsedivident[i-1]='0';

}else{

for(i=1;i<=16;i++)divident[i-1]=divident[i];

}if(node==0)

divident[i-1]=concatdata[j];else

divident[i-1]=frame[j];}divident[i-1]='\0';printf("\ncrc is %s\n",divident);if(node==0){strcpy(src_crc,divident);}elsestrcpy(dest_crc,divident);

} int main(){

int i,len,rest; printf("\n\t\t\tAT SOURCE NODE\n\nenter the data to be send :"); gets(data);

strcpy(concatdata,data);

System Software Lab Manual 21 / 55

Page 22: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

strcat(concatdata,"0000000000000000"); for(i=0;i<=16;i++)

divident[i]=concatdata[i];

divident[i+1]='\0'; crc_cal(0); printf("\ndata is :\t"); puts(data); printf("\nthe frame transmitted is :\t"); printf("\n%s%s",data,src_crc); printf("\n\t\tSOURCE NODE TRANSMITTED THE FRAME ---->"); printf("\n\n\n\n\t\t\tAT DESTINATION NODE\nenter the received frame:\t"); gets(frame); for(i=0;i<=16;i++)

divident[i]=frame[i]; divident[i+1]='\0'; crc_cal(1); if(strcmp(dest_crc,res)==0)

printf("\nreceived frame is error free "); else

printf("\nreceived frame has one or more error"); return 1;

}

OUTPUT : RUN 1:

$ cc prog1.c$ ./a.out

AT SOURCE NODEenter the data to be send :110011

crc is 0000011000110000data is : 110011the frame transmitted is :

1100110000011000110000

SOURCE NODE TRANSMITTED THE FRAME ----> AT DESTINATION NODEenter the received frame: 1100110000011000110000

crc is 0000000000000000

received frame is error free

RUN 2:

System Software Lab Manual 22 / 55

Page 23: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

AT SOURCE NODEenter the data to be send :110011crc is 0000011000110000data is : 110011the frame transmitted is :

1100110000011000110000

SOURCE NODE TRANSMITTED THE FRAME ----> AT DESTINATION NODEenter the received frame: 1100110000011000110001crc is 0000000000000001

received frame has one or more error

2. Write a program for frame sorting technique used in the buffers.

FRAME SORTING TECHNIQUE USED IN BUFFERS

Overview & Theoretical Concepts:

We need the frame sorter when the frame source is using TCP/IP so we can run packet re-assemblers on other computers in an effort to balance the workload.

If the frames are coming in over ISIS IP multicasts, we don't need a sorter: Each re-assembler can receive all frames and discard those they don't need. This way we get each frame on the network one time only, and the work in each re-assembler to input and reject frames on the wrong virtual channel is very little. If ISIS is not using true IP multicasting, then, once again, the sorter is needed to reduce the network traffic.

There are side benefits to such a design. In cases like I&T where the frame source is using TCP/IP, we need to sort the transfer frames by virtual channel so we can run some packet re-assemblers on other workstations to balance the compute load. But even so, we may re-assemble housekeeping packets on the workstation doing the frame sorting. Why do it in a separate process? This is especially true on Solaris where we have control over thread binding, and therefore, thread concurrency.

In a multi-threaded environment, the frame sorter and packet re-assembler both can be constructed from a collection of objects: input tasks, output tasks, packet assembly tasks, pool objects, sorter objects, and queue objects.

The packet re-assembler might looks like this:

System Software Lab Manual 23 / 55

Page 24: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

input --> queue --> pkt assy --> sorter --> queue --> output

Transfer frames enter an input. Input enqueues and possibly archives them. The packet assembly task reads frames out of the queue and constructs packets. It hands completed packets to a sorter which enqueues them for output tasks and possibly archives them. Each output task reads packets from its queue and sends packets out.

PROGRAM :

#include<stdio.h>struct frame{

int seq;char data[20];

};struct frame array[20],temp;int n;void sort(){

int i,j;for(i=0;i<n;i++)

for(j=0;j<n-1-i;j++)if(array[j].seq > array[j+1].seq){

temp=array[j];array[j]=array[j+1];array[j+1]=temp;

}}int main(){

int i;printf("\nenter the no. of frames:\t");scanf("%d",&n);for(i=0;i<n;i++){

printf("\nenter the seq no:\t");scanf("%d",&array[i].seq);printf("\nenter the data :\t");scanf("%s",&array[i].data);

}sort();printf("\nthe sorted frame is:\n");printf("\nthe seq no\t and data is\n");

for(i=0;i<n;i++)

System Software Lab Manual 24 / 55

Page 25: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

{ printf("%d\t %s\n",array[i].seq,array[i].data); }return 1;}

OUTPUT :$ cc prog2.c$ ./a.outenter the no. of frames: 5

enter the seq no: 3enter the data : hsr

enter the seq no: 5enter the data : reva

enter the seq no: 1enter the data : hi

enter the seq no: 4enter the data : from

enter the seq no: 2enter the data : am

the sorted frame is:

the seq no and data is

1 hi2 am3 hsr4 from5 reva

3. Write a program for distance vector algorithm to find suitable path for transmission.

System Software Lab Manual 25 / 55

Page 26: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

DISTANCE VECTOR ALGORITHM :

One of the most popular & dynamic routing algorithms, the distance vector routing algorithms operate by using the concept of each router having to maintain a table( ie., a vector ), that lets the router know the best or shortest distance to each destination and the next hop to get to there. Also know as Bellman Ford(1957) and Ford Fulkerson (1962). It was the original ARPANET algorithm.

Algorithm Overview:

Each router maintains a table containing entries for and indexed by each other router in the subnet. Table contains two parts :

1.A preferred outing line.2.Estimate of time or distance to that destination.

The metric used here is the transmission delay to each destination. This metric maybe number of hops, queue length, etc.

The router is assumed to know the distance metric to each of its neighbours.Across the network the delay is calculated by sending echo packets to each of neighbours.

PROGRAM :

#include<stdio.h>

struct rtable{

int dist[20],nextnode[20];}table[20];

int cost[10][10],n;void distvector(){

int i,j,k,count=0;for(i=0;i<n;i++){

for(j=0;j<n;j++){

table[i].dist[j]=cost[i][j];table[i].nextnode[j]=j;

}}

do {

System Software Lab Manual 26 / 55

Page 27: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

count=0;for(i=0;i<n;i++){

for(j=0;j<n;j++){for(k=0;k<n;k++)

{if(table[i].dist[j]>cost[i][k]+table[k].dist[j]){

table[i].dist[j]=table[i].dist[k]+table[k].dist[j];table[i].nextnode[j]=k;count++;

}}

}}

}while(count!=0);}

int main(){

int i,j;printf("\nenter the no of vertices:\t");scanf("%d",&n);printf("\nenter the cost matrix\n");for(i=0;i<n;i++)

for(j=0;j<n;j++)scanf("%d",&cost[i][j]);

distvector();for(i=0;i<n;i++){

printf("\nstate value for router %c \n",i+65);printf("\ndestnode\tnextnode\tdistance\n");for(j=0;j<n;j++){

if(table[i].dist[j]==99)printf("%c\t\t-\t\tinfinite\n",j+65);

elseprintf("%c\t\t%c\t\t%d\n",j+65,table[i].nextnode[j]+65,table[i].dist[j]);

} }return 0;

}

OUTPUT :

System Software Lab Manual 27 / 55

Page 28: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

$ cc prog3.c$ ./a.outenter the no of vertices: 6enter the cost matrix

0 2 1 99 99 12 0 99 2 1 991 99 0 99 2 2 99 2 99 0 1 599 1 2 1 0 991 99 2 5 99 0

state value for router A

destnode nextnode distanceA A 0B B 2C C 1D B 4E B 3F F 1

state value for router B

destnode nextnode distanceA A 2B B 0C A 3D D 2E E 1F A 3state value for router C

destnode nextnode distanceA A 1B A 3C C 0D E 3E E 2F F 2

state value for router D

System Software Lab Manual 28 / 55

Page 29: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

destnode nextnode distanceA B 4B B 2C E 3D D 0E E 1F F 5

state value for router E destnode nextnode distanceA B 3B B 1C C 2D D 1E E 0F B 4

state value for router F destnode nextnode distanceA A 1B A 3C C 2D D 5E A 4F F 0

4. Using TCP/IP sockets, write a client-server program to make client sending the file name and the server to send back the contents of the requested file if present.

CLIENT SERVER PROGRAM USING SOCKET PROGRAMMING

i. OVERVIEW

Unix sockets is just like two way FIFO's. All data communication will take place through the socket's interface, instead of through the file interface. Although unix socket's are a special file in the file system(just like FIFO's), there's usage of socket(), bind(), recv(),etc and not open(), read().

When programming with socket's, usually there's creation of server and client programs. The server will sit listening for incoming connections from clients and handling. This is similar to the situation that exists with internet sockets but with fine differences.

For instance, when describing which unix socket that has to be used(i.e the path to the special file that is the socket). The structure “struct sockaddr_un” has the following fields:

struct sockaddr_un{

System Software Lab Manual 29 / 55

Page 30: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

unsigned short sa_family; // Address family,AF_XXXX char sa_data; // 14 bytes of protocol address };

This is the structure you will be passing to the bind() function, which associates a socket descriptor(a file descriptor) with a certain file(the name for which is in the sun_path field).

The structure “struct sockaddr_in” is used when we need IP address and Port number to be binded to the Sockets. It has following fields:

struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address

unsigned char sin_zero[8] // Same size as struct sockaddr };

// Internet adress struct in_addr { unsigned long s_addr; // 32 bits or 4 bytes long

};ii. BACKGROUND REQUIRED:

1. UNIX File I/O system calls2. UNIX IPC system calls3. UNIX socket programming

iii. THEORETICAL CONCEPTS:

Most interprocess communication uses the client server model. These terms refer to the two processes which will be communication with each other. One of the two processes , the client , connects to the other process, the server, typiceally to make a request for information. A good analogy is a person who makes a phone call to another person.

Notice that the client needs to know of the existence of and the address of the server, but the server does not need to know the adresss of(or even the existence of) the client prior to the connection being established. Notice also that once a connection is established, both sides can send and receive information.

The system calls for establishing a connection are somewhat different for the client and the server, but both involve the basic construct of a socket. A socket is one end of an interprocess communication channel. The two processes each establish their own socket.

The steps involved in establishing a socket on the client side are as follows-1. Create a socket with the socket() system call .2. Connect the socket to the address of the server using the connect() system call.3. Send and receive data.There are a number of ways to do this, but the simplest is to use the

read() and write() systen calls.

The stepd involved in establishing a socket on the server side are as follows-

System Software Lab Manual 30 / 55

Page 31: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

1. Create a socket with the socket() system call.2. Bind the socket to an address using the bind() system call. For a server socket on the internet,an

address consists of a port number on the host machine.3. Listen for connections with the listen() system call.4. Acept a connection with the accept() system call. This call typically blocks until a client

connects with the server.5. Send and receive the data.

Socket Types:

When a socket is created, the program has to specify the address domain and the socket type. Two processes can communicate with each other only if their sockets are of the same type and in the same domain, in which two processes running on any two hosts on the Internet communicate. Each of these has it's own adress format.

The address of a socket in the Unix domain is a character string which is basically an entry in the file system. The address of a socket in the Internet domain consists of the Internet address of the host machine (every computer on the Internet has a unique 32 bit address, often reffered to as it's IP address). In addition , each socket needs a port number on that host. Port numbers are 16 bit unsigned integers. The lower numbers are reserved in Unix for standard services. For eg, the port number for the FTP server is 21.

There are two widely used socket types, stream sockets , and datgram sockets. Stream sockets treat communications as a continuous stream of characters, while datagram sockets have to read entire messages at once. Each uses it's own communications protocol. Stream sockets use TCP , which is a reliable , stream oriented protocol, and datagram sockets use UDP, which is unreliable and message oriented.

The primary socket calls are as follows:-1. socket() - Create a new socket and return it's descriptor.2. bind() - Associate a socket with a port and address .3. Listen() -Establish a queue for connection requests.4. Accept()- Accepts a connection request.5. Connect()- Initiate a connection to a remote host.6. Recv() - Receive data from a socket descriptor.7. Send() - Send data to a socket descriptor.8. Close() - “one-way” close of a socket descriptor,

The other system calls used are as follows:-1. gethostbyname- given a hostname , returns a structure which specifies it's DNS name(s) and IP

address(es).2. getservbyname – given service name and protocol , returns a structure which specifies its name(s)

and its port address.The socket utility functions are as follows:-

1. htons/ntohl- convert short/long from host byte order to network byte order.2. inet_ntoa/inet_addr- converts 32 bit IP address (network byte order to/from a dotted decimal string)The header files used in order are:-

System Software Lab Manual 31 / 55

Page 32: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

1.<sys/types.h> -prerequisite typedefs.2. <errno.h> -names for “erno” values (error numbers)3. <sys/socket.> - struct sock addr ;system prototypes and constants .4. <netdb.h.h> - network info lookup prototypes and structures.5. <netinet/in.h> - struct sockaddr_in; byte ordering macros.6. <arpa/inet.h> - utility function prototypes.

PROGRAM :

CLIENT :

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<netdb.h>#include<string.h>

void error(char *msg){

perror(msg);exit(0);

}int main(int argc,char *argv[]){

int sockfd,portno,n;struct sockaddr_in serv_addr;struct hostent *server;char filepath[256],buf[3000];if(argc < 3){

fprintf(stderr,"usage %s hostname port\n",argv[0]);exit(0);

}portno=atoi(argv[2]);sockfd=socket(AF_INET,SOCK_STREAM,0);if(sockfd<0)

error("\nerror in opening socket");printf("\nclient online");server=gethostbyname(argv[1]);if(server==NULL){

fprintf(stderr,"error ,no such host");exit(0);

}printf("\n server online");

System Software Lab Manual 32 / 55

Page 33: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

bzero((struct sockaddr_in *)&serv_addr,sizeof(serv_addr));serv_addr.sin_family=AF_INET;bcopy((char *)server->h_addr,(char *)&serv_addr.sin_addr.s_addr,server->h_length);serv_addr.sin_port=htons(portno);if(connect(sockfd,(struct sockaddr_in*)&serv_addr,sizeof(serv_addr))<0)

error("error writing to socket");printf("\nclient:enter path with filename:\n");scanf("%s",filepath);n=write(sockfd,filepath,strlen(filepath));if(n<0)

error("\nerror writing to socket");bzero(buf,3000);n=read(sockfd,buf,2999);if(n<0)

error("\nerror reading to socket");printf("\nclient:displaying from socket");fputs(buf,stdout);return 0;

}

SERVER :

#include<stdio.h>#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>

void error(char *msg){ perror(msg); exit(1);}

int main(int argc,char *argv[]){ int sockfd,newsockfd,portno,clilen,n,i=0; char buffer[256],c[2000],ch; struct sockaddr_in serv_addr,cli_addr; FILE *fd; if(argc < 2) { fprintf(stderr,"ERROR,no port provided\n"); exit(1); }sockfd=socket(AF_INET,SOCK_STREAM,0);

System Software Lab Manual 33 / 55

Page 34: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

if(sockfd<0) error("ERROR opening socket");bzero((char*) &serv_addr,sizeof(serv_addr));

portno=atoi(argv[1]);serv_addr.sin_family=AF_INET;serv_addr.sin_addr.s_addr=INADDR_ANY;serv_addr.sin_port=htons(portno);

if(bind(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)error("ERROR on binding");listen(sockfd,5);clilen=sizeof(cli_addr);printf("SERVER:Waiting for client....\n");newsockfd=accept(sockfd,(struct sockaddr*) &cli_addr,&clilen);if(newsockfd<0) error("ERROR on accept");bzero(buffer,256);n=read(newsockfd,buffer,255);if(n<0)error("ERROR reading from socket");printf("SERVER:%s \n",buffer);if((fd=freopen(buffer,"r",stdin))!=NULL) { printf("SERVER:%s found! \n Transfering the contents ...\n",buffer);

while((ch=getc(stdin))!=EOF)c[i++]=ch;c[i]='\0';

printf("File content %s\n",c);n=write(newsockfd,c,1999);if(n<0)error("ERROR in writing to socket");

}

else { printf("SERVER:File not found!\n"); n=write(newsockfd,"File not found!",15);

if(n<0)error("ERROR writing to socket");

}return 0;}

OUTPUT : AT TERMINAL 1 : (SERVER)

System Software Lab Manual 34 / 55

Page 35: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

$ cc prog4s.c$ ./a.out 7000

SERVER:Waiting for client....SERVER:hsr.cSERVER:hsr.c found! Transfering the contents ...File content #include<stdio.h>int main(){

printf("\nascii of a %d",'h'); return 1;}

AT TERMINAL 2 : (CLIENT)

$ cc prog4c.c$ ./a.out 127.0.0.1 7000

client online server onlineclient:enter path with filename:hsr.c

client:displaying from socket#include<stdio.h>int main(){

printf("\nascii of a %d",'h'); return 1;

}

5. Implement the above program using as message queues of FIFOs as IPC channel.

MESSAGE QUEUES / FIFOs AS IPC CHANNELS

FIFO's is used to send data between a Client and Server. If we have a server that is contacted by numerous clients, each client can write its request to a well-known(i.e, the pathname is known by all clients) FIFO that the server creates. The figure below shows this arrangement. Since there are multiple writers for the FIFO, the requests sent by the clients to the server need to be less than PIPE_BUF bytes in size. This prevents any interleaving of the client writes.

The problem in using FIFO's for this type of client-server communication is how to send replies back from the server to each client. A single FIFO can't be used, as the clients would never know when to read their response, versus responses for other clients. One solution is for each client to send its process ID with the request. The server then creates a unique FIFO for each client, using a pathname based on the client's process ID.

System Software Lab Manual 35 / 55

Server

Page 36: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

ii. BACKGROUND REQUIRED:

1. UNIX File I/O system calls2. UNIX IPC system calls

iii. ALGORITHM: There are two programs- Server side & Client side.

Server side:1. Create a well-known FIFO using “mknod” command.

Ex: mknod(<fifo name>, S_IFIFO | 0666 , 0)2. Open the above FIFO in readonly mode to accept requests from the clients.3. When the client opens the other end of FIFO in writeonly mode then read the contents

and store the request(pathname of file) in a buffer.4. Now create another FIFO(client-specific) in writeonly mode to send the reply(contents of

the file requested) 5. Open the file requested by client and write the contents into the client-speicfic FIFO and

terminate the connection. Client side:

1. Open the well-known Server FIFO in write mode.2. Write the pathname of file into this FIFO and send as a request.3. Now open the Client-specific FIFO in read mode and wait for reply from server.4. When the contents of file are available on this FIFO display it on the terminal.

PROGRAM :

System Software Lab Manual 36 / 55

Well-knownFIFO

Client Client

Client-specificFIFO

Client-specificFIFO

Page 37: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

CLIENT :

#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#include<unistd.h>

#define FIFO1_NAME "fifo1"#define FIFO2_NAME "fifo2"

int main(){ char p[100],f[100],c[3000]; int num,num2,f1,fd,fd2; mknod(FIFO1_NAME,S_IFIFO|0666,0); mknod(FIFO2_NAME,S_IFIFO|0666,0); printf("\n waiting for server...\n"); fd=open(FIFO1_NAME,O_WRONLY); printf("\n SERVER ONLINE !\n CLIENT:Enter the path\n"); while(gets(p),!feof(stdin)) { if((num=write(fd,p,strlen(p)))==-1) perror("write error\n"); else { printf("Waiting for reply....\n"); fd2=open(FIFO2_NAME,O_RDONLY); if((num2=read(fd2,c,3000))==-1) perror("Transfer error!\n"); else { printf("File recieved! displaying the contents:\n"); if(fputs(c,stdout)==EOF)

perror("print error\n"); exit(1); } } }}

SERVER :

System Software Lab Manual 37 / 55

Page 38: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#include<unistd.h>#define FIFO1_NAME "fifo1"#define FIFO2_NAME "fifo2"

int main(){

char p[100],f[100],c[300],ch;int num,num2,f1,fd,fd2,i=0;

mknod(FIFO1_NAME,S_IFIFO |0666,0);mknod(FIFO2_NAME,S_IFIFO |0666,0);

printf("\nSERVER ONLINE");fd=open(FIFO1_NAME,O_RDONLY);printf("client online\nwaiting for request\n\n");while(1){

if((num=read(fd,p,100))==-1)perror("\nread error");

else{

p[num]='\0';if((f1=open(p,O_RDONLY))<0){

printf("\nserver: %s not found",p);exit(1);

}else{ printf("\nserver:%s found \ntranfering the contents",p);

stdin=fdopen(f1,"r");while((ch=getc(stdin))!=EOF)

c[i++]=ch;c[i]='\0';printf("\nfile contents %s\n ",c);fd2=open(FIFO2_NAME,O_WRONLY);if(num2=write(fd2,c,strlen(c))==-1)

perror("\ntranfer error");

System Software Lab Manual 38 / 55

Page 39: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

elseprintf("\nserver :tranfer completed");

}exit(1);

}}

}

OUTPUT : AT TERMINAL 1:$ cc prog5s.c$ ./a.out

SERVER ONLINE client onlinewaiting for request

server:hsr.c foundtranfering the contentsfile contents #include<stdio.h>int main(){

printf("\nascii of a %d",'h'); return 1;

}

server :tranfer completed

AT TERMINAL 2: $ cc prog5c.c

$ ./a.out

waiting for server...

SERVER ONLINE ! CLIENT:Enter the path

hsr.cWaiting for reply....File recieved! displaying the contents:#include<stdio.h>int main(){

printf("\nascii of a %d",'h'); return 1;

}

6. Write a program for simple RSA algorithm to encrypt and decrypt the data.

System Software Lab Manual 39 / 55

Page 40: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

RSA ALGORITHM :

The RSA Public key algorithm was invented in 1977 by Ron Rivest, Adi Shamir and Leonard Adleman (RSA). The algorithm Supports Encryption and Digital Signatures. It is the most widely used public key algorithm. RSA gets its security from the integer factorization problem. The algorithm is relatively easy to understand and implement. It has been patent free since 2000. RSA is used in security protocols such as IPSEC/IKE -IP data security,TLS/SSL -transport data security (web), PGP -email security,SSH -terminal connection security,SILC -conferencing service security.

Theoretical Concepts:

RSA gets its security from the factorization problem. The difficulty of factoring large numbers is the basis of security of RSA.

The Integer factorization problem (finding a number's prime factors):

For a positive integer n, find its prime factors: n = p1 p2 ... pi where pi is positive distinct prime number

Example: 257603 = 41 * 61 * 103

Factorization algorithms can be used to factor faster than brute forcing. Some of them are Trial division, Pollard's rho, Pollard's p-1, Quadratic sieve, elliptic curve factorization, Random square factoring, Number field sieve, etc.

A Prime number is a positive integer and is divisible only by itself and 1. Prime numbers are found with primality testing; an algorithm which tests a probable prime for primality. If primality testing returns false prime numbers the cryptographic algorithm may be insecure (or will not function correctly).

RSA depends on prime numbers in key generation. It also uses strong primes, numbers whose � �factors of the prime are also primes.

The RSA algorithm:

Key generation:

1)Select random prime numbers p and q, and check that p != q

2)Compute modulus n = pq

3)Compute phi = (p - 1)(q - 1)

4)Select public exponent e, 1 < e < phi such that gcd(e,phi) = 1

System Software Lab Manual 40 / 55

Page 41: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

5)Compute private exponent d = e^-1 mod phi

6)Public key is {n, e}, private key is d

Encryption: c = me mod n, decryption: m = cd mod n

The selected public exponent e, which is used as public key with n. It is used to encrypt messages and to verify digital signatures. The e is stored for later with n. The e is usually small number but it can be 1 < e < phi . The e must be relatively prime to phi , hence gcd(e, phi ) = 1.(gcd = greatest common divisor, using the Euclidean algorithm)

The private exponent d, is the actual RSA private key. The d must not be disclosed at any time or the security of the RSA is compromised. The d is found by computing the multiplicative inverse d = e^-1 mod phi . The extended Euclidean algorithm is commonly used to compute inverses. The d exponent is used to decrypt messages and to compute digital signatures. Implementations try to find as small d as possible to make decryption faster. This is fine as long as it is assured that d is about the same size as n. If it is only one quarter of size it is not considered safe to be used. It is possible to find a smaller d by using lcm(p-1,q-1) instead of phi (lcm = least common multiple, lcm(p-1,q-1) = phi /gcd(p-1,q-1) ).

Example of RSA with small numbers:

p = 47, q = 71, compute n = pq = 3337

Compute phi = 46 * 70 = 3220

Let e be 79, compute d = 79-1 mod 3220 = 1019

Public key is n and e, private key d, discard p and q.

Encrypt message m = 688, 68879 mod 3337 = 1570 = c.

Decrypt message c = 1570, 15701019 mod 3337 = 688 = m.

PROGRAM :

#include<stdio.h>#include<math.h>

int gcd(int a,int b){

int r;while(b!=0){

r=a%b;a=b;

System Software Lab Manual 41 / 55

Page 42: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

b=r;}return a;

}long cal(long text,long key,long n){

long res=1,i;for(i=0;i<key;i++)

res=(res%n)*text;res=res%n;return res;

}

int main(){

long a,b,n,x,y,i,j,temp;char ciper[20],decrp[20];char text[20];printf("\n enter prime no.1:\t");scanf("%d",&a);printf("\n enter prime no.2:\t");scanf("%d",&b);n=a*b;temp=(a-1)*(b-1);for(i=2;i<temp;i++){

if(gcd(temp,i)==1){

x=i;break;

}}printf("\nthe value of public key is {%d , %d}",x,n);for(j=2;j<temp;j++){

if(((j*x)%temp)==1){

y=j;break;

}}printf("\nthe value of private key is {%d , %d}",y,n);printf("\nenter the plain text:");scanf("%s",text);i=0;printf("\ncipher text is:\t");

System Software Lab Manual 42 / 55

Page 43: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

while(text[i]!='\0'){

ciper[i]=cal(text[i]-97,x,n);printf("%c ",ciper[i]+97);decrp[i]=cal(ciper[i],y,n)+97;i++;

} printf("\n the received text is %s",decrp);return 0;

}

OUTPUT : RUN 1:

$ ./a.out enter prime no.1: 5

enter prime no.2: 11the value of public key is {3 , 55}the value of private key is {27 , 55}enter the plain text:revaitm

cipher text is: s j v a r � x the received text is revaitm

RUN 2: enter prime no.1: 7enter prime no.2: 5

the value of public key is {5 , 35}the value of private key is {5 , 35}

enter the plain text:revaitm

cipher text is: m j v a i y r the received text is revaitm

7. Write a program for Hamming Code generation for error detection and correction.

System Software Lab Manual 43 / 55

Page 44: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

HAMMING CODESOverview:Hamming codes are used for detecting and correcting single bit errors in transmitted data. This

requires that 3 parity bits (check bits) be transmitted with every 4 data bits. The algorithm is called A(7, 4) code, because it requires seven bits to encode 4 bits of data.

Eg: Bit String Parity Bit Verification

000 0 0 + 0 + 0 + 0 = 0001 1 0 + 0 + 1 + 1 = 0010 1 0 + 1 + 0 + 1 = 0011 0 0 + 1 + 1 + 0 = 0100 1 1 + 0 + 0 + 1 = 0101 0 1 + 0 + 1 + 0 = 0110 0 1 + 0 + 1 + 0 = 0111 1 1 + 1 + 1 + 1 = 0

Parity types:Even: - Even number of 1’s is present, i.e. the modulo 2 sum of the bits is 0.Odd: - Odd number of 1’s is present, i.e. the modulo 2 sum of the bits is 1.

Given data bits D1, D2, D3 and D4, A (7, 4) Hamming code may define parity bits P1, P2 and P3 as,P1=D2+D3+D4P2=D1+D3+D4P3=D1+D2+D4

There are 4 equations for a parity bit that may be used in Hamming codes,

P4=D1+D2+D3

Valid Hamming codes may use any 3 of the above 4 parity bit definitions. Valid Hamming codes may also place the parity bits in any location within the block of 7 data and parity bits.

One method for transferring 4 bits of data into a 7 bit Hamming code word is to use a 4x7 generate matrix [G] defined to be the 1x4 vector [D1 D2 D3 D4].

Its possible to create a 4x7 generator matrix [G] such that the product modulo 2 of d and [G] (D[G]) is the desired 1x7 Hamming code word.

For example each data bits can be represented with in a column vector as follows.

D1=

1

D2=

0

D3=

0

D4=

00 1 0 00 0 1 00 0 0 1

And represent each parity bit with a column vector continuing a 1 in the row corresponding to each data bit included in the computation and a zero in all other rows.

System Software Lab Manual 44 / 55

Page 45: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

P1=

0

P2=

1

P3=

11 0 11 1 01 1 1

And

G=

0 1 1 1 0 0 01 0 1 0 1 0 01 1 0 0 0 1 01 1 1 0 0 0 1

P1 P2 P3 D1 D2 D3 D4

EncodingThe process to encode the data value 1010 using the Hamming code defined by the G matrix is as

follows: -

[1010]

0 1 1 1 0 0 01 0 1 0 1 0 01 1 0 0 0 1 01 1 1 0 0 0 1

=

(1*0)+ (0*1)+ (1*1)+ (0*1)

=

0+0+1+0

=

1(1*1)+ (0*0)+ (1*1)+ (0*1) 1+0+1+0 0(1*1)+ (0*1)+ (1*0)+ (0*1) 1+0+0+0 1(1*1)+ (0*0)+ (1*0)+ (0*0) 1+0+0+0 1(1*0)+ (0*1)+ (1*0)+ (0*0) 0+0+0+0 0(1*0)+ (0*0)+ (1*1)+ (0*0) 0+0+1+0 1(1*0)+ (0*0)+ (1*0)+ (0*1) 0+0+0+0 0

Therefore 1010 encodes into 1011010. Equivalent Hamming codes represented by different generator matrices will produce different results.

DecodingThe first step is to check the parity bits to determine if there is an error. Arithmetically, parity may be

checked as follows: -P1 = D2+D3+D4 = 0+1+1 = 0P2 = D1+D3+D4 = 1+1+1 = 1P3 = D1+D2+D4 = 1+0+1 = 0

Parity may also be validated by using matrix operation. A 3x7 parity check matrix [H] may be constructed such that row 1 contains 1s in the position of the first parity bits and all the data bits that are included in its parity calculation. Using this, matrix [H] may be defined as follows: -

System Software Lab Manual 45 / 55

Page 46: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

H=1 0 0 0 1 1 10 1 0 1 0 1 10 0 1 1 1 0 1

3rd Bit Parity2nd Bit Parity

1st Bit Parity

Multiplying the 3x7 matrix [H] by a 7x1 matrix representing the encoded data produces a 3x1 matrix called the Syndrome.

If the syndrome is all 0’s the encoded data is error free. If the syndrome has a non-zero value, flipping the encoded bit that is in the position of the column matching the syndrome will result in a valid code word.Ex: -

Suppose the data received is 1011011, Then

11 0 0 0 1 1 1 00 1 0 1 0 1 1 1 (1*1)+(0*0)+(0*1)+(0*1)+(1*0)+(1*1)+(1*1) 10 0 1 1 1 0 1 1 = (0*1)+(1*0)+(0*1)+(1*1)+(0*0)+(1*1)+(1*1) = 1

0 (0*1)+(0*0)+(1*1)+(1*1)+(1*0)+(0*1)+(1*1) 111

Looking back at the matrix [H] the 7th column is all 1s so the 7th bit is the bit that has an error.

PROGRAM :

#include<stdio.h>#include<math.h>main(){

int i,j,k,count,error_pos=0,flag=0;char dw[20],cw[20],data[20];printf("enter the data as binary bit stream 7 bits\n");scanf("%s",data);for(i=1,j=0,k=0;i<12;i++){

if(i==(int)pow(2,j)){

dw[i]='?'; j++;

}else

System Software Lab Manual 46 / 55

Page 47: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

{dw[i]=data[k];k++;

}}

for(i=0;i<4;i++) {

count=0;for(j=(int)pow(2,i);j<12;j+=(int)pow(2,i)){

for(k=0;k<(int)pow(2,i);k++){

if(dw[j]=='1') count++; j++;

}}if(count%2 == 0)

dw[(int)pow(2,i)]='0';else

dw[(int)pow(2,i)]='1';}printf("\n CODE WORD is \n\n");for(i=1;i<12;i++)

printf("%c",dw[i]);printf("\n\nenter the received hamming code\n\n");scanf("%s",cw);for(i=12;i>0;i--)

cw[i]=cw[i-1];for(i=0;i<4;i++){

count=0; for(j=(int)pow(2,i);j<12;j+=(int)pow(2,i))

{ for(k=0;k<(int)pow(2,i);k++) { if(cw[j]=='1') count++; j++; }

} if(count%2 != 0) error_pos=error_pos+(int)pow(2,i);

}

System Software Lab Manual 47 / 55

Page 48: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

if(error_pos ==0)printf("\n\n There is no ERROR in received Code Word\n");

else{ if(cw[error_pos]==dw[error_pos])

{printf("\n\nThere are TWO or MORE Errors in received Code Word\n\n");printf("SORRY........! Hamming code cannot correct TWO or MORE Errors\n"); flag=1;}

elseprintf("\nThere is an Error in bit position %d of received Code Word \n\n",error_pos);

if(flag==0){if(cw[error_pos]=='1')

cw[error_pos]='0';else

cw[error_pos]='1';printf("\n\nCORRECTED CODE WORD is \n\n");for(i=1;i<12;i++)

printf("%c",cw[i]);}

}

printf("\n\n");}

OUTPUT :RUN 1 :

$ cc -lm prog7.c$ ./a.outenter the data as binary bit stream 7 bits1100111

CODE WORD is01111001111enter the received hamming code01111001111

There is no ERROR in received Code Word

RUN 2:

$ ./a.outenter the data as binary bit stream 7 bits1100111

CODE WORD is

System Software Lab Manual 48 / 55

Page 49: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

01111001111enter the received hamming code11111001111There is an Error in bit position 1 of received Code WordCORRECTED CODE WORD is01111001111

8. Write a program for Congestion control using the leaky bucket algorithm.

LEAKY BUCKET ALGORITHM

The leaky-bucket implementation is used to control the rate at which traffic is sent to the network. A leaky bucket provides a mechanism by which bursty traffic can be shaped to present a steady stream of traffic to the network, as opposed to traffic with erratic bursts of low-volume and high-volume flows.

Traffic analogy An appropriate analogy for the leaky bucket is a scenario in which four lanes of automobile traffic converge into a single lane. A regulated admission interval into the single lane of traffic flow helps the traffic move. The benefit of this approach is that traffic flow into the major arteries (the network) is predictable and controlled. The major liability is that when the volume of traffic is vastly greater than the bucket size, in conjunction with the drainage-time interval, traffic backs up in the bucket beyond bucket capacity and is discarded.

● The Leaky-bucket algorithm

The algorithm can be conceptually understood as follows:● Arriving packets (network layer PDUs) are placed in a bucket with a hole in the bottom. ● The bucket can queue at most b bytes. If a packet arrives when the bucket is full, the packet is

discarded. ● Packets drain through the hole in the bucket, into the network, at a constant rate of r bytes per

second, thus smoothing traffic bursts.

The size b of the bucket is limited by the available memory of the system.Sometimes the leaky bucket and token algorithms are lumped together under the same name.PROGRAM :

System Software Lab Manual 49 / 55

Page 50: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

#include<stdio.h>#include<stdlib.h>int trand(int a){

int rn;rn=random()%10;rn=rn%a;if(rn==0)

rn=1;return(rn);

}

int main(){

int i,packet[5],psz,bsz,pszrn=0,clk,ptime,premain,orate,flag=0;for(i=0;i<5;i++)

packet[i]=trand(6)*10;printf("\nenter the o/p rate");scanf("%d",&orate);printf("\nenter the bucket size");scanf("%d",&bsz);for(i=0;i<5;i++){

if((packet[i]+pszrn)>bsz)printf("\n incoming packet size %d is greater than bucket size_reject",packet[i]);

else{

for(;;){premain=4-i;psz=packet[i];pszrn+=psz;printf("\nincoming packet size is %d",psz);printf("\n no.of packets waiting for transmission= %d",pszrn);ptime=trand(4)*10;printf("\nnext packet will come at %d",ptime);for(clk=0;clk<=ptime;clk++){

printf("\ntime left =%d",ptime-clk);sleep(1);if(pszrn){

if(pszrn==0)printf("\nbucket is empty");

else

System Software Lab Manual 50 / 55

Page 51: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

{if(pszrn>=orate)

printf("%d bytes are tranmited",orate);else

printf("\n %d bytes are transmitted",pszrn);}if(pszrn<=orate)

pszrn=0;else

pszrn-=orate;printf("\nbytes remaining %d ",pszrn);

}else

printf("\nbytes remaing %d ",pszrn);}if(pszrn!=0)

flag=1;break;

}}

}printf("\n\n");return 0;

}

OUTPUT : RUN 1:

$ cc prog8.c$ ./a.outenter the o/p rate10enter the bucket size5

incoming packet size 30 is greater than bucket size_reject incoming packet size 10 is greater than bucket size_reject incoming packet size 10 is greater than bucket size_reject incoming packet size 50 is greater than bucket size_reject incoming packet size 30 is greater than bucket size_reject

RUN 2:

enter the o/p rate5enter the bucket size10

incoming packet size 30 is greater than bucket size_reject

System Software Lab Manual 51 / 55

Page 52: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

incoming packet size is 10 no.of packets waiting for transmission= 10next packet will come at 10time left =105 bytes are tranmitedbytes remaining 5 time left =95 bytes are tranmitedbytes remaining 0 time left =8bytes remaing 0 time left =7bytes remaing 0 time left =6bytes remaing 0 time left =5bytes remaing 0 time left =4bytes remaing 0 time left =3bytes remaing 0 time left =2bytes remaing 0 time left =1bytes remaing 0 time left =0bytes remaing 0 incoming packet size is 10 no.of packets waiting for transmission= 10next packet will come at 20time left =205 bytes are tranmitedbytes remaining 5 time left =195 bytes are tranmitedbytes remaining 0 time left =18bytes remaing 0 time left =17bytes remaing 0 time left =16bytes remaing 0 time left =15bytes remaing 0 time left =14bytes remaing 0 time left =13bytes remaing 0 time left =12bytes remaing 0

System Software Lab Manual 52 / 55

Page 53: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

time left =11bytes remaing 0 time left =10bytes remaing 0 time left =9bytes remaing 0 time left =8bytes remaing 0 time left =7bytes remaing 0 time left =6bytes remaing 0 time left =5bytes remaing 0 time left =4bytes remaing 0 time left =3bytes remaing 0 time left =2bytes remaing 0 time left =1bytes remaing 0 time left =0bytes remaing 0 incoming packet size 50 is greater than bucket size_reject incoming packet size 30 is greater than bucket size_reject

Viva Questions

1. What are functions of different layers?2. Differentiate between TCP/IP Layers and OSI Layers3. Why header is required?4. What is the use of adding header and trailer to frames?5. What is encapsulation?6. Why fragmentation requires?7. What is MTU?8. Which layer imposes MTU?9. Differentiate between flow control and congestion control.10. Differentiate between Point-to-Point Connection and End-to-End connections.11. What are protocols running in different layers?12. What is Protocol Stack?13. Differentiate between TCP and UDP.14. Differentiate between Connectionless and connection oriented connection.15. Why frame sorting is required?16. What is meant by subnet?17. What is meant by Gateway?18. What is an IP address?

System Software Lab Manual 53 / 55

Page 54: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

19. What is MAC address?20. Why IP address is required when we have MAC address?21. What is meant by port?22. What are ephemerical port number and well known port numbers?23. What is a socket?24. What are the parameters of socket()?25. Describe bind(), listen(), accept(),connect(), send() and recv().26. What are system calls? Mention few of them.27. What is IPC? Name three techniques.28. Explain mkfifo(), open(), close() with parameters.29. What is meant by file descriptor?30. What is meant by traffic shaping?31. How do you classify congestion control algorithms?32. Differentiate between Leaky bucket and Token bucket.33. How do you implement Leaky bucket?34. How do you generate busty traffic?35. What is the polynomial used in CRC-CCITT?36. What are the other error detection algorithms?37. What is difference between CRC and Hamming code?38. Why Hamming code is called 7,4 code?39. What is odd parity and even parity?40. What is meant by syndrome?41. What is generator matrix?42. What is spanning tree?43. Where Pirm’s algorithm does finds its use in Networks?44. Differentiate between Prim’s and Kruskal’s algorithm.45. What are Routing algorithms?46. How do you classify routing algorithms? Give examples for each.47. What are drawbacks in distance vector algorithm?48. How routers update distances to each of its neighbor?49. How do you overcome count to infinity problem?50. What is cryptography?51. How do you classify cryptographic algorithms?52. What is public key?53. What is private key?54. What are key, ciphertext and plaintext?55. What is simulation?56. What are advantages of simulation?57. Differentiate between Simulation and Emulation.58. What is meant by router?59. What is meant by bridge?60. What is meant by switch?61. What is meant by hub?62. Differentiate between route, bridge, switch and hub.63. What is ping and telnet?64. What is FTP?65. What is BER?66. What is meant by congestion window?67. What is BSS?68. What is incoming throughput and outgoing throughput?69. What is collision?

System Software Lab Manual 54 / 55

Page 55: untitled [atriacs2010.weebly.com]atriacs2010.weebly.com/uploads/1/2/2/4/1224879/cn_lab... · Web viewAverage no: of TCP packets sent = varying (348 to 1100) Average no: of UDP packets

REVA ITM Dept of Information Science & Engg

70. How do you generate multiple traffics across different sender-receiver pairs?71. How do you setup Ethernet LAN?72. What is meant by mobile host?73. What is meant by NCTUns?74. What are dispatcher, coordinator and nctunsclient?75. Name few other Network simulators76. Differentiate between logical and physical address.77. Which address gets affected if a system moves from one place to another place?78. What is ICMP? What are uses of ICMP? Name few.79. Which layer implements security for data?

System Software Lab Manual 55 / 55