Lab Manual Cn

83
1 DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING NETWORKS LABORATORY (V SEMESTER) MANUAL PREPARED BY VERIFIED BY APPROVED BY Ms. P.SUMATHY Ms.B.RENUA Dr.C.S.RAVICHANDRAN SSK College of Engineering & Technology Coimbatore-641 105 (An ISO 9001:2008 Certified Institution)

Transcript of Lab Manual Cn

Page 1: Lab Manual Cn

1

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

ENGINEERING

NETWORKS LABORATORY

(V SEMESTER)

MANUAL

PREPARED BY VERIFIED BY APPROVED BY

Ms. P.SUMATHY Ms.B.RENUA Dr.C.S.RAVICHANDRAN

SSK College of Engineering & Technology Coimbatore-641 105

(An ISO 9001:2008 Certified Institution)

Page 2: Lab Manual Cn

2

SYLLABUS:

080290035 NETWORKS LABORATORY

1. Implementation of Error Detecting Codes(CRC)2. Implementation of IP subnet3. Ethernet LAN protocol4. To create scenario and study the performance of CSMA/CD protocol simulation

5. Token bus and token ring protocols: To create scenario and study the performance of token bus and token ring protocols through simulation.

6. Wireless LAN protocols: To create scenario and study the performance of network with CSMA / CA protocol and compare with CSMA/CD protocols.

7. Implementation and study of stop and wait protocol.8. Implementation and study of Go-back-N and selective reject protocols.9. Implementation of distance vector routing algorithm.10. Implementation of Link state routing algorithm.11. Implementation of Data encryption and decryption.

*Open Source Software Tools like Ethereal /Wireshark Opnet IT Guru, NetworkSimulator 2, Router Simulator may be used for Simulation.

Page 3: Lab Manual Cn

3

LIST OF EXPERIMENTS:

CYCLE 01

1. Study the performance of CSMA/CD2. Study and implementation of STOP & WAIT Protocol3. Study the performance of CSMA/CA4. Token Bus5. Token Ring6. Study and implementation of sliding window Go Back-N7. Study and implementation of sliding window Selective Repeat8. Implementation of Distance Vector Routing Algorithm

CYCLE 02

9. Implementation of Link State Routing10. Data encryption and decryption using RC4 Algorithm11. Study the performance of CSMA/CD using NS2 simulation12. Study the performance of token bus using NS2 simulation13. Study the performance of token ring using NS2 simulation14. Study of error detecting code Cyclic Redundancy Check (CRC)15. STUDY of IP Subnet

Page 4: Lab Manual Cn

4

INDEX

S.No. Name of the experiment Page No. Remarks

1 STUDY THE PERFORMANCE OF CSMA/CD 5

2 STUDY AND IMPLEMENTATION OF STOP &

WAIT PROTOCOL

11

3 STUDY THE PERFORMANCE OF CSMA/CA 18

4 TOKEN BUS 23

5 TOKEN RING 28

6 STUDY AND IMPLEMENTATION OF SLIDING

WINDOW GO BACK-N

33

7 STUDY AND IMPLEMENTATION OF SLIDING

WINDOW SELECTIVE REPEAT

39

8 IMPLEMENTATION OF DISTANCE VECTOR

ROUTING ALGORITHM

44

9 IMPLEMENTATION OF LINK STATE ROUTING 51

10 DATA ENCRYPTION AND DECRYPTION USING

RC4 ALGORITHM

57

11 STUDY THE PERFORMANCE OF CSMA/CD

USING NS2 SIMULATION

61

12 STUDY THE PERFORMANCE OF TOKEN BUS

USING NS2 SIMULATION

65

13 STUDY THE PERFORMANCE OF TOKEN RING

USING NS2 SIMULATION

73

14 STUDY OF ERROR DETECTING CODE CYCLIC

REDUNDANCY CHECK (CRC)

78

15 STUDYOF IP SUBNET 80

Page 5: Lab Manual Cn

5

1. STUDY THE PERFORMANCE OF CSMA/CD

AIM:

Implement the CSMA/CD protocol for packet communication between a numbers of

nodes connected to a common bus.

EQUIPMENTS REQUIRED:

(a) Computer with Benchmark LanT software

(b) Hardware emulator kit.

THEORY:

It augments the CSMA algorithm to handle the collision. In this method, a station

monitors the medium after it sends a frame to see if the transmission was successful. If so, the

station is finished. If, however, there is a collision, the frame is sent again. The throughput of

CSMA/CD is greater than that of pure or slotted ALOHA. The basic idea is that a station needs

to be able to receive while transmitting to detect a collision. When there is no collision, the

station receives one signal; its own signal. When there is collision, the station receives two

signals; its own signal and signal transmitted by a second station.

PROCEDURE:

1. Click on the MAC Experiment icon twice from the desktop on both PC’s.

2. Click the Configuration button in the window in both the PC’s.

Page 6: Lab Manual Cn

6

Page 7: Lab Manual Cn

7

Page 8: Lab Manual Cn

8

Page 9: Lab Manual Cn

9

TABULATION:

IPD TX1 TX2 TX3 TX4 G-OFFERED LOAD

X-THROUGHPUT

Page 10: Lab Manual Cn

10

RESULT:

Thus the implementation of CSMA/CD Protocol for packet communication between a number of nodes connected to a common bus.

Page 11: Lab Manual Cn

11

2. STUDY AND IMPLEMENTATION OF STOP & WAIT PROTOCOL

AIM:

(i) To study the performance of Stop and Wait protocol and find its throughput.

(ii) To plot Timeout (T) Vs Throughput (X) for various Ts.

(iii) To plot BER Vs X for various BERs {10-2,10-3,10-4,10-5,10-6}

EQUIPMENTS REQUIRED:

(i) Computer with benchmark LanT software

(ii) Hardware emulator kit.

THEORY:

In a stop and wait method of flow control, the sender waits for an acknowledgement after

every frame it sends. Only when an acknowledgement has been received, the next frame is sent.

This process of alternately sending and waiting repeats until the sender transmits on end of

transmission frame. The advantage is simplicity and the disadvantage is its inefficiency.

Stop and wait ARQ is a form of stop and wait flow control extended to include

retransmission of data in case of damaged frames. For retransmission to work, four features are

added to the basic flow control mechanism.

The sending device keeps a copy of the last frame transmitted until it receives an

acknowledgement for that frame. Keeping a copy allows the sender to retransmit lost or damaged

frames until they are received correctly.

For identification purposes with data frames and ACK frames are numbered alternately 0

and 1. An ACK 1 frame, indicating that the receiver has gotten data 0 and is now expecting data

1, acknowledges a data 0 frame. This numbering allows for identification allows for

identification of data frames in case of duplicate transmission.

If an error is discovered in a data frame, indicating that it has been corrupted in transit, a

NAK frame is returned. NAK frames, which are not numbered, tell the sender to retransmit the

last frame sent. Stop and wait ARQ requires that the sender waits till it receives an

Page 12: Lab Manual Cn

12

acknowledgement for the frame, last sent by it, before it transmits the next one. When the sender

receives a NAK, it retransmits the frame sent after the previous ACK, irrespective of the number.

The sending device is equipped with a timer.

Page 13: Lab Manual Cn

13

Page 14: Lab Manual Cn

14

Page 15: Lab Manual Cn

15

PROCEDURE FOR BER:

Page 16: Lab Manual Cn

16

TABULATION:

BER=0

TIME OUT VALUE IN ms SUCCESSFULLY TX PACKETS X-PRACTICAL THROUGHPUT

TABULATION:

THT=1000

BER SUCCESSFULLY TX PACKETS

THEORETICAL THROUGHPUT

PRACTICAL THOUGHPUT

Page 17: Lab Manual Cn

17

RESULT:

Thus the STOP AND WAIT protocol was studied and graph was plotted.

Page 18: Lab Manual Cn

18

3. STUDY THE PERFORMANCE OF CSMA/CA

AIM:

To perform file transfer and data transfer using different topoloies in wireless LAN protocol.

THEORY:

Wireless LAN is basically a LAN that transmits data over air without any physical

connection between devices. The transmission medium is a form of electromagnetic radiation

wireless LAN is rectified by IEEE in the IEE 8021 standard. The underlaying algorithm used in

wireless LAN is known as the CSMA/CA - Carrier Sense Multiple Access/ Collision Avoidance

algorithm the working of CSMA/CD algorithm. The approach called CSMA/CA is adopted by

the IEEE 802.11 wireless LAN standard. In CSMA/CA, if the station finds the channel busy, it

does not restart the timer of the contention window; it stops the timer and restarts it when the

channel becomes idle. When an idle channel is found, the station does not send immediately. It

waits for a period of time the interframe space or IFS. If after the IFS time the channel is still

idle, the station can send, but it still needs to wait a time equal to the contention time.

The mode has data to transmit senses the medium, if the medium has been idle for layer

than the DIFS. It finishes its back off interval and transmits request to send signal immediately.

PROCEDURE:

1. Open the protocol always activate to 100 link into configuration addressed and the server.

2. These details must be shown for the source and estimation.

3. Value the network connection in that disable LAN and enable the wireless LAN.

4. Then select Vi-Rt sim and can do any type of process such that token ring, token bus, PC to

PC and so on.

5. Put the IP address and transfer the data and receive it.

6. The output is noted in system.

Page 19: Lab Manual Cn

19

TIMING DIAGRAM:

PCF- Point Cordination Function

DCT-Distributed Cordination Function

DIFS-Distributed Interface Space

RTS-Request To Send

CTS-Clear To Send

NAV- Network Allocation Vector

RTS- CTS- Handshakin

Page 20: Lab Manual Cn

20

OUTPUT:

Page 21: Lab Manual Cn

21

Page 22: Lab Manual Cn

22

RESULT:

Thus, the transfer of file, data is done using different topologies by wireless LAN.

Page 23: Lab Manual Cn

23

4. TOKEN BUS

AIM:

To implement the token passing access in BUS-LAN.

EQUIPMENTS REQUIRED:

(i) Computer with Benchmark LanT software

(ii) Hardware emulator kit.

THEORY:

Token bus was a 4Mbps local area networking technology created by IBM to connect

their terminals to mainframes. Token bus utilized a copper coaxial cable to connect multiple. The

coaxial cable saved as a common communication bus and a token was created by token bus

protocol to manage or arbitrate access to the bus.

Any station that has token packet has permission to transmit data. The station releases

token when it is done communication or when a higher priority device needs to transmit. Token

bus suffered two major limitations-any failure in bus caused all the devices beyond failure to be

able to communicate with rest of the network. Secondly adding more stations to bus was

difficult. Token bus was thus seen as unreliable and difficult to expand and upgrade.

Token ring was created by IBM to improve upon the previous bus technology. Token

ring uses a ring-based technology and passes a token around the network to control access to

network wiring. The token ring protocol also provides features for allowing delay sensitive

traffic to share network with other data that is key to mainframe operations.

Page 24: Lab Manual Cn

24

Page 25: Lab Manual Cn

25

Page 26: Lab Manual Cn

26

Page 27: Lab Manual Cn

27

TABULATION:

IPD TX1 TX2 TX3 TX4 G-Offered Load X-Throughput Avg Delay

RESULT:

Thus the implementation of token passing access in BUS-LAN

Page 28: Lab Manual Cn

28

5. TOKEN RING

AIM:

To implement the token passing access in RING-LAN.

EQUIPMENTS REQUIRED:

(i) Computer with Benchmark LanT software(ii) Hardware emulator kit.

THEORY:

Token bus was a 4Mbps local area networking technology created by IBM to connect

their terminals to mainframes. Token bus utilized a copper coaxial cable to connect multiple. The

coaxial cable saved as a common communication bus and a token was created by token bus

protocol to manage or arbitrate access to the bus.

Any station that has token packet has permission to transmit data. The station releases

token when it is done communication or when a higher priority device needs to transmit. Token

bus suffered two major limitations-any failure in bus caused all the devices beyond failure to be

able to communicate with rest of the network. Secondly adding more stations to bus was

difficult. Token bus was thus seen as unreliable and difficult to expand and upgrade.

Token ring was created by IBM to improve upon the previous bus technology. Token

ring uses a ring-based technology and passes a token around the network to control access to

network wiring. The token ring protocol also provides features for allowing delay sensitive

traffic to share network with other data that is key to mainframe operations.

Page 29: Lab Manual Cn

29

Page 30: Lab Manual Cn

30

Page 31: Lab Manual Cn

31

Page 32: Lab Manual Cn

32

TABULATION:

IPD TX1 TX2 TX3 TX4 G-Offered Load X-Throughput Avg Delay

RESULT:

Thus the implementation of token passing access in RING-LAN.

Page 33: Lab Manual Cn

33

6. STUDY AND IMPLEMENTATION OF SLIDING WINDOW GO BACK-N

AIM:

(i) To study the performance of Go-Back-N protocol and find its throughput.

(ii) To plot G Vs X for various values of T {100,250,500,750,1500,3000} and various

window sizes Ws {2,4,8}

(iii) To plot BER Vs X for Ws =4

EQUIPMENTS REQUIRED:

(i) Computer with benchmark LanT software

(ii) Hardware emulator kit.

THEORY:

In this sliding window Go-Back_N ARQ method, if one frame is lost or damaged, all

frames sent since the last frame acknowledge are retransmitted.

Damaged Frame: When the frames 0, 1, 2 and 3 have been transmitted but the first

acknowledgement received is a NAK 3, there are 2 meanings for the NAK. First, a positive

acknowledgement of all frames received prior to the damaged frame and second, a negative

acknowledgement of the frame indicated. If the first acknowledgement of the indicated is a NAK

3, it means that data frames 0,1 and 2 were all received in good shape. Only frame 3 must be

resent. If frames 0 through 4 have been transmitted before a NAK is received, the receiver

discovers and error, it stops accepting subsequent frames until the damaged frame has been

replaces correctly.

Lost data frame: Sliding window protocols require that the data frame be transmitted

sequentially. If one or more frames are noise corrupted that they are lost in transit, the next frame

that arrives at the receiver will be out of sequence. The receiver that one or more have skipped

and returns a NAK for the first missing frames. A NAK frame does not indicate whether the

frame has been lost or damaged, first that it means to be resent. The sending device then

retransmits the frame indicated by the NAK, as well as any frame that it had transmitted after the

last one.

Page 34: Lab Manual Cn

34

Page 35: Lab Manual Cn

35

Page 36: Lab Manual Cn

36

TABULATION

BER=0

TIME OUT VALUE IN ms SUCCESSFULLY TX PACKETS X-PRACTICAL THROUGHPUT

PROCEDURE FOR GOBACK-N WITH BER:

Page 37: Lab Manual Cn

37

TABULATION:

BER Successfully Tx packets

Theorectical throughput

Practical throughput

Page 38: Lab Manual Cn

38

RESULT:

Thus the SLIDING WINDOW GO BACK-N protocol was implemented and graph was plotted.

Page 39: Lab Manual Cn

39

7. STUDY AND IMPLEMENTATION OF SLIDING WINDOW SELECTIVE REPEAT

AIM: (i) To study the performance of Selective Repeat protocol and find its throughput.

(ii) To plot G Vs X for various values of T {100,250,500,750,1500,3000} and various

window sizes Ws {2,4,8}

(iii) To plot BER Vs X for Ws =4

EQUIPMENTS REQUIRED:

(i) Computer with benchmark LanT software

(ii) Hardware emulator kit.

Page 40: Lab Manual Cn

40

Page 41: Lab Manual Cn

41

TABULATION:

Time out values in ms Successfully Tx packets Practical Throughput

Page 42: Lab Manual Cn

42

PROCEDURE FOR SELECTIVE REPEAT WITH BER:

Page 43: Lab Manual Cn

43

TABULATION:

BER Successfully Tx packets

Theorectical throughput

Practical throughput

RESULT:

Thus the SLIDING WINDOW SELECTIVE REPEAT protocol was implemented and graph was plotted.

Page 44: Lab Manual Cn

44

8. IMPLEMENTATION OF DISTANCE VECTOR ROUTING ALGORITHM

AIM:

To implement the distance vector routing algorithm

EQUIPMENTS REQUIRED:

(I) Computer with routing simulator software.

THEORY:

In routing, the pathway with the lowest cost is considered the best. As long as the

cost of each link is known, a router can find the optimal combination for any transmission.

Several routing algorithms exist for making these calculations. The most popular are the distance

vector and the link state routing algorithm.

DISTANCE VECTOR ROUTING:

In this method, each router periodically shares its knowledge about the entire

network with its neighbors. The three keys to understanding how this algorithm works are

knowledge about the whole network, routing only to neighbors, information sharing at regular

intervals. Distance vector routing simplifies the routing process by assuming a cost of one unit

for every link. In this way, the efficiency of transmission is a function only of the number of

links required to reach a destination. In distance vector routing, the cost of is based on hop count.

A router sends its knowledge to its neighbors. The neighbors add this knowledge to their own

knowledge and send the whole table to their own neighbors. Eventually, every router knows

about other router in the internetwork.

Page 45: Lab Manual Cn

45

Page 46: Lab Manual Cn

46

Page 47: Lab Manual Cn

47

Page 48: Lab Manual Cn

48

Page 49: Lab Manual Cn

49

Page 50: Lab Manual Cn

50

RESULT:

Thus the Distance vector routing algorithm was implemented.

Page 51: Lab Manual Cn

51

9. IMPLEMENTATION OF LINK STATE ROUTING

AIM:

To implement the link state routing algorithm

EQUIPMENTS REQUIRED:

(i) Computer with routing simulator software.

THEORY:

In routing, the pathway with the lowest cost is considered the best. As long as the

cost of each link is known, a router can find the optimal combination for any transmission.

Several routing algorithms exist for making these calculations. The most popular are the distance

vector and the link state routing algorithm.

LINK STATE ROUTING:

In this state routing, each router shares its knowledge of its neighborhood with

every other router in the internetwork. In link state algorithm, the keys are, knowledge about the

neighborhood, to all routers, information sharing when there is a change. A router gets its

information about its neighbors by periodically sending them a short greeting packet. If the

neighbor responds to the greeting as expected, it is assumed to be alive and functioning. If it does

not, a change is assumed to have occurred and the sending router then alerts the rest of the

network in its next LSP. In link state routing, every router has exactly the same link state

database.

Page 52: Lab Manual Cn

52

Page 53: Lab Manual Cn

53

Page 54: Lab Manual Cn

54

Page 55: Lab Manual Cn

55

Page 56: Lab Manual Cn

56

RESULT:

Thus the Link state routing algorithm was implemented.

Page 57: Lab Manual Cn

57

10. DATA ENCRYPTION AND DECRYPTION USING RC4 ALGORITHM

AIM

To encrypt a file using RC4 encryption algorithm and decrypt the same.

EQUIPMENTS REQUIRED:

(i) Computer with encryption and decryption software.

THEORY:

To carry sensitive information such as military or financial data, a system must be able to

assure privacy. Microwave, satellite and other wireless media, however, cannot be protected

from the unauthorized reception (or interception) of transmission. Even cable systems cannot

always prevent unauthorized access. Cables pass through out-of-the-way areas (such as

basements) that provide opportunities for malicious access to access to the cable and illegal

reception of information.

It is unlikely that any system can completely prevent unauthorized access to transmission

media. A more practical way to protect information is to alter it so that only an authorized

receiver can understand it. Data tampering is not a new issue, nor is it unique to the computer

era.

In fact, there are methods to make information unreadable b unauthorized receivers. The

method used today is called the encryption and decryption of information. Encryption means that

the sender transforms the original information to another form and sends the resulting

unintelligible message out over the network. Decryption reverses the encryption process in order

to transform the message back to its original form.

The sender uses an encryption algorithm and a key to transfer the plaintext (the original

message) into a cipher text (the encrypted message). The receiver uses a decryption algorithm

and a key to transform the cipher text back to the original plaintext.

Page 58: Lab Manual Cn

58

Initial Setup:

1. Browse ‘C:\Lantrain\DataSecurity’.

2. Copy the ‘RC4’ folder and three class files (Connect, RC4Client, Server) and

paste it into the ‘Java\jdk1.5\bin’ folder in both the server and client PC’s

Setting up the Server:

1. Open command prompt window (Start _Run _ type ‘cmd’).

2. Browse the java bin folder.

3. Type ‘java Server’ to run the server.

Encrypting a file:

1. Open command prompt in the client side.

2. Browse the java bin folder.

3. Type ‘java RC4Client’.

4. Enter the IP address of the server.

5. Enter the mode of operation.

6. Enter the Encryption key not more than 5 characters.

7. Enter the path name of the file to be encrypted. (for eg: c:\\abc.txt)

Page 59: Lab Manual Cn

59

8. Type YES if you like to close the session or type NO if you like to continue

Decrypting the ‘Cipher text’.

9. The encrypted text is available in c:\output.txt.

10. Try to re-arrange the cipher text using any crypt-analysis tool.

Decrypting the Cipher text file:

1. Enter the mode of operation as DEC for decrypting the cipher text.

2. Enter the Decryption key same as used for Encryption.

3. Enter the full path name of the file to be decrypted. (i.e., c:\\output.txt)

4. Find out the decrypted file in c:\\output.txt.

Page 60: Lab Manual Cn

60

RESULT:

Thus the RC4 encryption algorithm was used to encrypt the file and decrypt the same.

Page 61: Lab Manual Cn

61

11. STUDY THE PERFORMANCE OF CSMA/CD USING NS2 SIMULATION

AIM:

To study and simulate the CSMA/CD protocol.

PROCEDURE:

1. Type the program in notepad and save itb as .tcl

2. Select Cygwin and type startx

3. To run the program type “ns file name’ in command window

4. The output structure of CSMA/CD is noted.

PROGRAM:

#send packets one by oneset ns [new Simulator]$ns color 1 Greenforeach i " 0 1 2 3 4 5 " { set n$i [$ns node] }$n0 color "purple"$n1 color "purple"$n2 color "violet"$n3 color "violet"$n4 color "chocolate"$n5 color "chocolate"$n0 shape box ;$n1 shape box ;$n2 shape box ;$n3 shape box ;$n4 shape box ;$n5 shape box ;$ns at 0.0 "$n0 label SYS1"$ns at 0.0 "$n1 label SYS2"$ns at 0.0 "$n2 label SYS3"$ns at 0.0 "$n3 label SYS4"$ns at 0.0 "$n4 label SYS5"$ns at 0.0 "$n5 label SYS6"set nf [open csma.nam w]$ns namtrace-all $nf

Page 62: Lab Manual Cn

62

set f [open csma.tr w]$ns trace-all $f$ns duplex-link $n0 $n2 0.1Mb 20ms DropTail$ns duplex-link-op $n0 $n2 orient right-down$ns queue-limit $n0 $n2 5$ns duplex-link $n1 $n2 0.1Mb 20ms DropTail$ns duplex-link-op $n1 $n2 orient right-up$ns duplex-link $n2 $n3 0.1Mb 20ms DropTail$ns duplex-link-op $n2 $n3 orient right$ns duplex-link $n3 $n4 0.1Mb 20ms DropTail$ns duplex-link-op $n3 $n4 orient right-up$ns duplex-link $n3 $n5 0.1Mb 20ms DropTail$ns duplex-link-op $n3 $n5 orient right-downAgent/TCP set nam_tracevar_ trueset tcp [new Agent/TCP]$tcp set window_ 1$tcp set maxcwnd_ 1$tcp set fid_ 1$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n2 $sink$ns connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcpset tcp1 [new Agent/TCP]$tcp1 set window_ 1$tcp1 set maxcwnd_ 1$tcp1 set fid_ 1$ns attach-agent $n1 $tcp1set sink1 [new Agent/TCPSink]$ns attach-agent $n2 $sink1$ns connect $tcp1 $sink1set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1set tcp2 [new Agent/TCP]$tcp2 set window_ 1$tcp2 set maxcwnd_ 1$tcp2 set fid_ 1$ns attach-agent $n1 $tcp2set sink2 [new Agent/TCPSink]$ns attach-agent $n0 $sink2$ns connect $tcp2 $sink2set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2set tcp3 [new Agent/TCP]

Page 63: Lab Manual Cn

63

$tcp3 set window_ 1$tcp3 set maxcwnd_ 1$tcp3 set fid_ 1$ns attach-agent $n0 $tcp3set sink3 [new Agent/TCPSink]$ns attach-agent $n1 $sink3$ns connect $tcp3 $sink3set ftp3 [new Application/FTP]$ftp3 attach-agent $tcp3$ns at 0.05 "$ftp start"$ns at 0.071 "$ns queue-limit $n2 $n0 0"$ns at 0.10 "$ns queue-limit $n2 $n0 5"$ns at 0.09 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n2 $sink" $ns at 0.25 "finish"$ns at 0.05 "$ftp1 start"$ns at 0.072 "$ns queue-limit $n2 $n1 0"$ns at 0.10 "$ns queue-limit $n2 $n1 5"$ns at 0.09 "$ns detach-agent $n1 $tcp1 ; $ns detach-agent $n2 $sink1" $ns at 0.25 "finish"$ns at 0.10 "$ftp2 start"$ns at 0.13 "$ns detach-agent $n0 $tcp2 ; $ns detach-agent $n1 $sink2" $ns at 0.25 "finish"$ns at 0.12 "$ftp3 start"$ns at 0.14 "$ns detach-agent $n1 $tcp1 ; $ns detach-agent $n0 $sink3" $ns at 0.25 "finish"$ns at 0.0 "$ns trace-annotate \"CSMA/CA\""$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.01\""$ns at 0.05 "$ns trace-annotate \"Send Packet_1 from SYS1 to SYS0 and Packet_2 from SYS0 to SYS1 \""$ns at 0.73 "$ns trace-annotate \"Collision Occurs so 2 Packets are lossed\""$ns at 0.10 "$ns trace-annotate \"Retransmit Packet_1 from SYS1 to SYS0 \""$ns at 0.12 "$ns trace-annotate \"Retransmit Packet_2 from SYS0 to SYS1 \""$ns at 0.20 "$ns trace-annotate \"FTP stops\""proc finish {} {

global ns nf$ns flush-traceclose $nf

puts "filtering..."#exec tclsh ../bin/namfilter.tcl csma.nam

#puts "running nam..." exec nam csma.nam &

exit 0}$ns run

Page 64: Lab Manual Cn

64

OUTPUT:

RESULT:

Thus the CSMA/CD protocol is simulated and verified.

Page 65: Lab Manual Cn

65

12. STUDY THE PERFORMANCE OF TOKEN BUS USING NS2 SIMULATION

AIM:To study and simulate the TOKEN BUS protocol.

PROCEDURE:

1. Type the program in notepad and save itb as .tcl

2. Select Cygwin and type startx

3. To run the program type “ns file name’ in command window

4. The output structure of CSMA/CD is noted.

PROGRAM:

set ns [new Simulator]set Bandwidth "0.5Mb"set packetsize 700set intval 0.004$ns color 1 magenta$ns color 2 seagreen$ns color 3 deepskyblue$ns color 4 brown$ns color 5 salmonforeach i "0 1 2 3 4 5 6" {set n$i [$ns node]}$n0 color "navy"$n1 color "salmon"$n2 color "seagreen"$n3 color "deepskyblue"$n4 color "steel blue"$n5 color "steel blue"$n6 color "steel blue"$ns at 0.0 "$n0 label Sender"$ns at 0.0 "$n1 label Receiver1"$ns at 0.0 "$n2 label Receiver2"$ns at 0.0 "$n3 label Receiver3"set nf [open tokenbus.nam w]$ns namtrace-all $nf

Page 66: Lab Manual Cn

66

set f [open tokenbus.tr w]$ns trace-all $f$ns duplex-link $n0 $n5 $Bandwidth 30ms DropTail$ns duplex-link $n5 $n2 $Bandwidth 30ms DropTail$ns duplex-link $n4 $n1 $Bandwidth 30ms DropTail$ns duplex-link $n4 $n5 $Bandwidth 30ms DropTail$ns duplex-link $n5 $n6 $Bandwidth 30ms DropTail$ns duplex-link $n6 $n3 $Bandwidth 30ms DropTail$ns duplex-link-op $n0 $n5 orient down$ns duplex-link-op $n5 $n2 orient down$ns duplex-link-op $n4 $n1 orient down$ns duplex-link-op $n4 $n5 orient right$ns duplex-link-op $n5 $n6 orient right$ns duplex-link-op $n6 $n3 orient down$ns queue-limit $n4 $n5 10set tcp1 [new Agent/TCP]$ns attach-agent $n0 $tcp1$tcp1 set fid_ 1 ;set tcp2 [new Agent/TCP]$ns attach-agent $n1 $tcp2$tcp2 set fid_ 1 ;set tcp3 [new Agent/TCP]$ns attach-agent $n2 $tcp3$tcp3 set fid_ 1 ;set tcp4 [new Agent/TCP]$ns attach-agent $n3 $tcp4$tcp4 set fid_ 1 ;set tcp5 [new Agent/TCP]$ns attach-agent $n0 $tcp5$tcp5 set fid_ 1 ;set tcp6 [new Agent/TCP]$ns attach-agent $n1 $tcp6$tcp6 set fid_ 1 ;set tcp7 [new Agent/TCP]$ns attach-agent $n2 $tcp7$tcp7 set fid_ 1 ;set tcp8 [new Agent/TCP]$ns attach-agent $n3 $tcp8$tcp8 set fid_ 1 ;set tcp9 [new Agent/TCP]$ns attach-agent $n0 $tcp9

Page 67: Lab Manual Cn

67

$tcp9 set fid_ 1 ;set tcp10 [new Agent/TCP]$ns attach-agent $n1 $tcp10$tcp10 set fid_ 1 ;set tcp11 [new Agent/TCP]$ns attach-agent $n2 $tcp11$tcp11 set fid_ 1 ;set tcp12 [new Agent/TCP]$ns attach-agent $n3 $tcp12$tcp12 set fid_ 1 ;set sink1 [new Agent/TCPSink]$ns attach-agent $n1 $sink1set sink2 [new Agent/TCPSink]$ns attach-agent $n2 $sink2set sink3 [new Agent/TCPSink]$ns attach-agent $n3 $sink3set sink4 [new Agent/TCPSink]$ns attach-agent $n0 $sink4set sink5 [new Agent/TCPSink]$ns attach-agent $n1 $sink5set sink6 [new Agent/TCPSink]$ns attach-agent $n2 $sink6set sink7 [new Agent/TCPSink]$ns attach-agent $n3 $sink7set sink8 [new Agent/TCPSink]$ns attach-agent $n0 $sink8set sink9 [new Agent/TCPSink]$ns attach-agent $n1 $sink9set sink10 [new Agent/TCPSink]$ns attach-agent $n2 $sink10set sink11 [new Agent/TCPSink]$ns attach-agent $n3 $sink11set sink12 [new Agent/TCPSink]$ns attach-agent $n0 $sink12$ns connect $tcp1 $sink1$ns connect $tcp2 $sink2$ns connect $tcp3 $sink3$ns connect $tcp4 $sink4$ns connect $tcp5 $sink5$ns connect $tcp6 $sink6$ns connect $tcp7 $sink7

Page 68: Lab Manual Cn

68

$ns connect $tcp8 $sink8$ns connect $tcp9 $sink9$ns connect $tcp10 $sink10$ns connect $tcp11 $sink11$ns connect $tcp12 $sink12set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2set ftp3 [new Application/FTP]$ftp3 attach-agent $tcp3set ftp4 [new Application/FTP]$ftp4 attach-agent $tcp4set ftp5 [new Application/FTP]$ftp5 attach-agent $tcp5set ftp6 [new Application/FTP]$ftp6 attach-agent $tcp6set ftp7 [new Application/FTP]$ftp7 attach-agent $tcp7set ftp8 [new Application/FTP]$ftp8 attach-agent $tcp8set ftp9 [new Application/FTP]$ftp9 attach-agent $tcp9set ftp10 [new Application/FTP]$ftp10 attach-agent $tcp10set ftp11 [new Application/FTP]$ftp11 attach-agent $tcp11set ftp12 [new Application/FTP]$ftp12 attach-agent $tcp12set udp0 [new Agent/UDP]$ns attach-agent $n1 $udp0$udp0 set fid_ 2 ;$tcp7 set fid_ 4 ;set cbr0 [new Application/Traffic/CBR]$cbr0 attach-agent $udp0set null0 [new Agent/Null]$ns attach-agent $n3 $null0$ns connect $udp0 $null0$cbr0 set packetSize_ $packetsize$cbr0 set interval_ $intvalset udp1 [new Agent/UDP]

Page 69: Lab Manual Cn

69

$ns attach-agent $n3 $udp1$udp1 set fid_ 2 ;$tcp8 set fid_ 4 ;set cbr1 [new Application/Traffic/CBR]$cbr1 attach-agent $udp1set null1 [new Agent/Null]$ns attach-agent $n0 $null1$ns connect $udp1 $null1$cbr1 set packetSize_ $packetsize$cbr1 set interval_ $intvalset udp2 [new Agent/UDP]$ns attach-agent $n3 $udp2$udp2 set fid_ 3 ;$tcp12 set fid_ 4;set cbr2 [new Application/Traffic/CBR]$cbr2 attach-agent $udp2set null2 [new Agent/Null]$ns attach-agent $n0 $null2$ns connect $udp2 $null2$cbr2 set packetSize_ $packetsize$cbr2 set interval_ $intval$ns at 0.05 "$ftp1 start"$ns at 0.13 "$ns detach-agent $n0 $tcp1;$ns detach-agent $n1 $sink1"$ns at 3.0 "finish"$ns at 0.14 "$ftp2 start"$ns at 0.20 "$ns detach-agent $n1 $tcp2;$ns detach-agent $n2 $sink2"$ns at 3.0 "finish"$ns at 0.23 "$ftp3 start"$ns at 0.30 "$ns detach-agent $n2 $tcp3;$ns detach-agent $n3 $sink3"$ns at 3.0 "finish"$ns at 0.33 "$ftp4 start"$ns at 0.40 "$ns detach-agent $n3 $tcp4;$ns detach-agent $n0 $sink4"$ns at 3.0 "finish"$ns at 0.42 "$ftp5 start"$ns at 0.50 "$ns detach-agent $n0 $tcp5;$ns detach-agent $n1 $sink5"$ns at 3.0 "finish"$ns at 0.51 "$ftp6 start"$ns at 0.60 "$ns detach-agent $n1 $tcp6;$ns detach-agent $n2 $sink6"$ns at 3.0 "finish"$ns at 0.62 "$ftp7 start"$ns at 0.69 "$ns detach-agent $n2 $tcp7;$ns detach-agent $n3 $sink7"

Page 70: Lab Manual Cn

70

$ns at 3.0 "finish"$ns at 0.725 "$ftp8 start"$ns at 0.78 "$ns detach-agent $n3 $tcp8;$ns detach-agent $n0 $sink8"$ns at 3.0 "finish"$ns at 0.83 "$ftp9 start"$ns at 0.90 "$ns detach-agent $n0 $tcp9;$ns detach-agent $n1 $sink9"$ns at 3.0 "finish"$ns at 0.93 "$ftp10 start"$ns at 1.0 "$ns detach-agent $n1 $tcp10;$ns detach-agent $n2 $sink10"$ns at 3.0 "finish"$ns at 1.03 "$ftp11 start"$ns at 1.1 "$ns detach-agent $n2 $tcp11;$ns detach-agent $n3 $sink11"$ns at 3.0 "finish"$ns at 1.13 "$ftp12 start"$ns at 1.2 "$ns detach-agent $n3 $tcp12;$ns detach-agent $n0 $sink12"$ns at 3.0 "finish"$ns at 0.621 "$cbr0 start"$ns at 0.69 "$cbr0 stop"$ns at 0.726 "$cbr1 start"$ns at 0.78 "$cbr1 stop"$ns at 1.131 "$cbr2 start"$ns at 1.2 "$cbr2 stop"proc finish {} { global ns nf$ns flush-traceclose $nfexec awk {{if(($1=="-" && $5=="tcp") || ($1=="-" && $5=="cbr")) {print $2 "\t" $11}}} tokenbus.tr > throughput.dataputs "filtering..."exec nam tokenbus.nam &exec xgraph throughput.data &exit 0}$ns run

Page 71: Lab Manual Cn

71

OUTPUT:

Page 72: Lab Manual Cn

72

RESULT:

Thus the TOKEN BUS protocol is simulated and verified.

Page 73: Lab Manual Cn

73

13. STUDY THE PERFORMANCE OF TOKEN RING USING NS2 SIMULATION

AIM:

To study and simulate the TOKEN RING protocol.

PROCEDURE:

1. Type the program in notepad and save itb as .tcl

2. Select Cygwin and type startx

3. To run the program type “ns file name’ in command window

4. The output structure of CSMA/CD is noted.

PROGRAM:

set ns [new Simulator]set Bandwidth "1Mb"set paketsize 700set intval 0.004set nf [open out.nam w]$ns namtrace-all $nfset f [open out.tr w]$ns trace-all $fset old_data 0proc finish {} {global ns nf$ns flush-traceclose $nfexec awk { {

if($1=="-"&& $5=="cbr") {print $2"\t"$11}

}} out.tr > throughput.dataexec nam out.nam &exec xgraph throughput.data &exit 0 }

Page 74: Lab Manual Cn

74

for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node]}$ns color 1 purple$ns color 2 green$ns color 3 darkgreenfor {set i 0} {$i < 6} {incr i} {$ns duplex-link $n($i) $n([expr ($i+1)%6]) $Bandwidth 10ms DropTail}set tcp1 [new Agent/TCP]$ns attach-agent $n(0) $tcp1$tcp1 set fid_ 1 ;set sink1 [new Agent/TCPSink]$ns attach-agent $n(3) $sink1$ns connect $tcp1 $sink1set ftp1 [new Application/FTP]$ftp1 attach-agent $tcp1set tcp2 [new Agent/TCP]$ns attach-agent $n(3) $tcp2$tcp2 set fid_ 1 ; set sink2 [new Agent/TCPSink]$ns attach-agent $n(5) $sink2$ns connect $tcp2 $sink2set ftp2 [new Application/FTP]$ftp2 attach-agent $tcp2set tcp3 [new Agent/TCP]$ns attach-agent $n(5) $tcp3$tcp3 set fid_ 1 ; set sink3 [new Agent/TCPSink]$ns attach-agent $n(2) $sink3$ns connect $tcp3 $sink3set ftp3 [new Application/FTP]$ftp3 attach-agent $tcp3set tcp4 [new Agent/TCP]$ns attach-agent $n(2) $tcp4$tcp4 set fid_ 1 ; set sink4 [new Agent/TCPSink]$ns attach-agent $n(4) $sink4$ns connect $tcp4 $sink4set ftp4 [new Application/FTP]

Page 75: Lab Manual Cn

75

$ftp4 attach-agent $tcp4set tcp5 [new Agent/TCP]$ns attach-agent $n(4) $tcp5$tcp5 set fid_ 1 ; set sink5 [new Agent/TCPSink]$ns attach-agent $n(0) $sink5$ns connect $tcp5 $sink5set ftp5 [new Application/FTP]$ftp5 attach-agent $tcp5set udp0 [new Agent/UDP]$ns attach-agent $n(5) $udp0$udp0 set fid_ 3 ; $tcp3 set fid_ 2 ;set cbr0 [new Application/Traffic/CBR]$cbr0 set interval_ $intval$cbr0 attach-agent $udp0set null0 [new Agent/Null]$ns attach-agent $n(2) $null0$ns connect $udp0 $null0$ns at 0.1 "$ftp1 start"$ns at 0.125 "$ns detach-agent $n(0) $tcp1; $ns detach-agent $n(3) $sink1"$ns at 1.0 "finish"$ns at 0.131 "$ftp2 start"$ns at 0.14 "$ns detach-agent $n(3) $tcp2; $ns detach-agent $n(5) $sink2"$ns at 1.0 "finish"$ns at 0.157 "$ftp3 start"$ns at 0.185 "$ns detach-agent $n(5) $tcp3; $ns detach-agent $n(2) $sink3"$ns at 1.0 "finish"$ns at 0.19 "$ftp4 start"$ns at 0.21 "$ns detach-agent $n(2) $tcp4; $ns detach-agent $n(4) $sink4"$ns at 1.0 "finish"$ns at 0.211 "$ftp5 start"$ns at 0.22 "$ns detach-agent $n(4) $tcp5; $ns detach-agent $n(0) $sink5"$ns at 1.0 "finish"$ns at 0.157 "$cbr0 start"#$ns rtmodel-at 1.0 down $n(1) $n(2)#$ns rtmodel-at 2.0 up $n(1) $n(2)$ns at 0.185 "$cbr0 stop"$ns at 1.0 "finish"$ns run

Page 76: Lab Manual Cn

76

OUTPUT:

Page 77: Lab Manual Cn

77

RESULT:

Thus the TOKEN RING protocol is simulated and verified.

Page 78: Lab Manual Cn

78

14. STUDY OF ERROR DETECTING CODE CYCLIC REDUNDANCY CHECK (CRC)

AIM:

To study a category of cyclic codes called the cyclic redundancy check (CRC) that is

used in networks such as LANs & WANs.

THEORY:

Cyclic codes are special linear block codes, which are extra property. In a cyclic code, if

a code word is cyclically shifted the result is another codeword.

ENCODER:

In the encoder, the data word has k bits the codeword has n bits. The size of the data

word is augmented by adding n-k, as to right hand side of the word. The n bit result is fed into

the generator. The generator uses a divisor of n-k+1, predefined and agreed assign. The

generator devices the quotient of the division in discarded the remainder is appended to the data

word to create the codeword.

Page 79: Lab Manual Cn

79

The generator devices the quotient of the divisor is dicarded the remainder is appended to the data

woed to create the code word. The process of module 2 binary division is same as the familiar division

process, are use free the decimal numbers. As in decimal division. The process is done step by step in

each step, a copy of the divisor is xored with the 4 bit of the divident the result of the XOR operation is 3

bit whish is used for next step after one extra bit is pulled down to make it 4 bit long. It left most bit of

divident is 0, the step cannot the regular divisor and need to use all 0 s divisor.

When there are no bits of left to pull down and have a result. The 3 bit remainder from the chech

bit (r2,r1 and r0) they are appended to the dataword to create codeword.

DECODER:

The decoder receives the possible output & codeword is copy of its n bits is fet to the

checker is a replace of the generator. The remainder produced by the checker is a syndrome of N-R bits,

which is fed to the divisor logic analyser. The analyser has a simple logic analysis function . If the

syndrome bits are all 0’s. The 4 left most bits of the codeword are accepted as the dataword otherwise the

4 bit are discarded.

The codeword can chane during transmission the decoder does the same division process as the

encoder. The remainder of the division is the syndrome. If the syndrome is all 0’s there is no error.

DIVISOR:

The divisor is repeatly XORed with part of the divident. One interesting point about the

communication window is that the station needs to sense the channels after each time slot.

ACKNOWLEDEMENT:

With all there precautions, there still may be a collision resulting in destroyed data.In addition,

data may be corrupted during the transmission. The positive acknowledgement and the timeout timer can

help guarantee that the receiver was received the frame.

RESULT:

Thus a category of cyclic codes called cyclic redundacy check was studied.

Page 80: Lab Manual Cn

80

15. STUDY OF IP SUBNET

AIM

To study IP subnet

THEORY

SUBNETTING:

During the era of classical addressing subnetting was introduced. If an organization was

granted a large book in class A or class B it could divide the address into several contiguous

groups and assigns each group to smaller networks called as subnets or in rare case share part of

the address with neighbors subnetting increases the number of 1s in the masks.

An organization that is granted a large block of addressing may want to create clusters of

networks and decade the address between the different subnet. The rest of the word still sees the

organization as one entity, however internally there are several subnets. All message, are sent to

the router address that connects the organization, however needs to create small sub-blocks of

address, each assigned to specific subnets. The organization has its own mask, each subnet mask

also have its own.

Let us check to see if we can find the subnet address from one of the address in the

subnet.

a) In subnet 1, the address 11.12.14.29/27 can gives us the subnet address, if we use the

mask/27 because

Host: 00010001 00001100 00001110 00011101

Mask/27

Subnet: 00010001 00001100 00001110 00000000.

17.12.14.0

b) In subnet 2, the address 17.12.14.45/28 can give us the subnet address, it we use the

mask/28 because

Page 81: Lab Manual Cn

81

Host: 00010001 00001100 00001110 00101101

Mask/28

Subnet: 00010001 00001100 00001110 00100000.

17.12.14.32

c) In subnet 3, the address 17.12.14.50/28 can give us the subnet address, it we use the

mask/28 because

Host: 00010001 00001100 00001110 00110010

Mask/28

Subnet: 00010001 00001100 00001110 00100000.

17.12.14.48

We can say that through subnetting, we have three levels of hierarchy. So the subnet

prefix length can differ for various subnets. More levels of hierarchy.

The structure of classless addressing does not restrict the number of hierarchical levels.

An organization can divide the granted blocks of address into smaller sub blocks and so on. One

example of this is seen in ISPS. A national ISP can divide a granted large block into smaller

block and assign each of them to a regional ISP. A regional ISP can divide the block received

from the national ISP smaller blocks and assign one to a different organization. Finally an

organization can divide smaller blocks and assigns each and make several subnets out of it.

ADDRESS ALLOCATION:

The next issue in classes addressing is address allocation. The ultimate responsibility of

address allocation is given to a global authority called the internet corporation for assigned

names and address (ICANN). However ICANN does not normally allocate address to individual

organization. It assigns a large block of address to an ISP. Each ISP in turn divides in assigned

block into smaller sub blocks and grants the sub blocks to its customers. In other words an ISP

receiver one large block to be distributed. This is called address propagation.

Page 82: Lab Manual Cn

82

Fig: SUBNET

Page 83: Lab Manual Cn

83

Fig: Three level hierarchy is an IP/4 address

RESULT:

Thus IP subnet was studied.