03-10-2016, 11:03 AM
1457436372-cnwlabmanual.doc (Size: 87.5 KB / Downloads: 5)
AIM:
SIMULATION OF BIT STUFFING
To write a C program that takes as binary file as input and performs bit stuffing.
ALGORITHM:
1. Create two files "input.dat" for accepting the binary input and "output.dat" for displaying the output. Initialize the variable count to O.
2. Get the choice from the user- Press 1 to perform BITSTUFFING and 2 to perform DESTUFFING.
3. If the user selects the BITSTUFFING option then 3.1 Get each character from the file
3.2 Check ifit is '0' . If yes then print it directly in the output file
3.3 Else increment count and check ifit is equal to 5. If yes, then print a '0' followed by the character that was read and set count to 0 else print the character directly in the output file.
4. If the user selects the DE STUFFING option,
4.1 Copy the content from output.dat to input1.dat which acts as the input file to de stuffing model.
4.2get each character from the inputl.dat file which holds the value of bit stuffed content.
4.3 print the character received from the input file in the output file. 4.4 Increment the count variable ifu read continous l's
4.5 If count reaches 5 and next character equals to 0 ,then continu~. the reading loop instead of printing it to the output file
4.6 Else,print the received bit to the outputfile and reinitialize the count to
O.
5. Close all the files.
3
SAMPLE RUN:
Enter your choice:
Options:
1 ~Bitstuff
2 ~ Bit Destuffing
1
Input.dat file contents before Bitstuffing 011111101011101010000001111110 Output.dat file contents after Bitstuffing 01111101010111010100000011111010
Enter your choice:
Options:
1 ~Bitstuff 2~Bit Destuffing 2
Inputl.dat file contents before Bit Destuffing 01111101010111010100000011111010
Output.dat file contents after Bit Destuffing 011111101011101010000001111110
SIMULATION OF CYCLIC REDUNDANT CODE
To write a C program to implement Cyclic Redundancy Check(CRC) technique.
ALGORITHM:
1. Get the inputs from the user for the length of the data frame n, Data frame D(x), Degree
of the generator polynomial r and the generator polynomial G(x).
2. Append (r-l) zeroes to the data frame,D(x). Print it as appended frame.
3. Perform XOR operation of generator polynomial and the corresponding bit stream of the data frame.
4. The check sum which is the remainder of the XOR operation is appended to the data frame instead of the appended(r-l) zeroes.
5. At the receiver, the received frame is once again XOR ed with the same generator polynomial and find the remainder.
6. If the remainder is zero ,then the received frame is correct,else it has some error.
SAMPLE RUN:
Enter the size of data frame (n) : 6 Enter the data frame D(x): 1 0 1 1 0 1
Enter the size of generator polynomial ( r):4 Enter the generator polynomial G(x) : 1 1 0 1 The appended frame is : 1 0 1 1 0 1 0 0 0
The checksummed frame is : 1 0 1 1 0 1 0 1 0
At receiver,
Received frame is : 1 0 1 1 0 1 0 1 0 G(x) is: 1 1 0 1
The checksummed frame is : 1 0 1 1 0 1 0 0 0
The received data is correct. At receiver sample 2:
Received frame is: 1 00 1 0 1 0 1 0 G(x) is: 1 1 0 1
The checksummed frame is : 1 0 1 1 0 1 0 0 1
The received data is incorrect.
5
Ex.No.3
TRANSFER OF FILES OVER RS232 (SERIAL)
AIM:
To communicate between PC to PC: Serial communication using RS 232C
ALGORITHM:
1. The executable file shows the options for sending or receiving information between two computers.
2. Type the information on the space below and press Enter key.
3. The indication there on the top of the screen shows whether the message is being sent or received.
4. If any message is received from another computer, it is displayed on the screen.
SIMULATION OF SLIDING WINDOW PROTOCOL
AIM:
To simulate the sliding window protocol to study how the technique for forwarding packets by minimizing the congestion in the network occurs.
ALGORITHM:
1. The packets are numbered from 1 to a maximum value of the number of
packets to be sent.
2. The window size at the transmitter and receiver are decided. 3. Random numbers are used to decide factors like
)- The packet is transmitted and received.
)- The sent packet is lost and must be retransmitted. )- The timer at the sender is expired.
)- 'The acknowledgement from receiver is lost )- Duplication of packets occurred
4. Depending upon a range of random numbers it is decided to simulate one of the events listed above.
5. If the acknowledgement is positive,then it starts reading the next packet of data
6. If acknowledgement is negative, then it retransmits for n times and shows the timer expired message.
7. If not EOP(End Of Packet) goto step 5.
SAMPLE RUN:
Prepare the items to send.
Enter the no of packets to be send : 3
Enter the data for packet[O] : 12
Enter the data for packet[ 1] : 44
Enter the data for packet[2] : 33
Sending data packet 1 .. Data packet 1 sent .
Do you want to acknowledge packet 1 (y/n)?y Data received is 12 ..
Sending data packet 2 .. Data packet 2 sent .
Do you want to acknowledge packet 2(y/n)?n Sending data packet 2 ..
Data packet 2 sent .
Do you want to acknowledge packet 2(y/n)?n Sending data packet 2 ..
Data packet 2 sent .
Do you want to acknowledge packet 2(y/n)?n
ACK Timer 1 seconds
ACK Timer 2 seconds
ACK Timer 3 seconds
Timer expired.
Data has to be retransmitted.
Do you want to retransmit packet 2(y/n)?y Sending data packet 2 ..
Data packet 2 sent.
Do you want to acknowledge packet 2(y/n)?y Data received is 44.
Sending data packet3 .. Data packet 3 sent .
Do you want to acknowledge packet 3(y/n)?y Data received is 33.
8
Ex.No.5
SIMULATION OF OSPF ROUTING PROTOCOL
AIM:
To simulate the OPEN SHORTEST PATH FIRST routing protocol based on the cost assigned to the path.
ALGORITHM:
1. Read the no. of nodes n
2. Read the cost matrix for the path from each node to another node.
3. Initialize SOURCE to 1 and include 1
4. Compute D of a node which is the distance from source to that corresponding node.
5. Repeat step 6 to step 8 for n-l nodes.
6. Choose the node that has not been included whose distance is minimum and include that node.
7. For every other node not included compare the distance directly from the source with the distance to reach the node using the newly included node
8. Take the minimum value as the new distance.
9. Print all the nodes with shortest path cost from source node
SAMPLE RUN:
Enter the no. of nodes (n) :4
Enter the cost matrix :
1 8 5 500
801 3
5 1 0 10
500 3 10 0
Node Shortest Path Cost
1 2 3 4
o 6 5 9
9
Ex.No.6
AIM:
CLIENT/SERVER APPLICATION FOR CHAT
To implement one to one chat using TCP ALGORITHM:
TCPCHATSERVER:
1. Get the port number from the command line argument.
2. Check the number of command line arguments. it must be 2, ifnot prompt an error
message
3. Clear the buffer using bzero function.
4. Establish the socket connection.
5. Assign local protocol addresses to the socket using bind function
6. Move the socket from the closed state to the listen state using the listen function and provide the maximum number of connections that the kernel could queue for the socket.
7. create a new socket connection using the client address with the help of accept
function.
8. if the socket connection is not established properly, prompt an error. 9. Read the data from the socket
9. write the data typed by the second user to the socket.If typed value is exit then chatting session stops else go back to step 9
TCPCHA TCLIENT:
1. Get the name and port number from the command line argument.
2. Check the number of command line arguments; it must be 3, if not prompt an error message.
3. Open the socket connection
4. Clear the buffer using bzero function
5. Write a request to the buffer that contains the request number as a byte to the
output stream
6. Establish a communication to a TCP server using connect functions 7. Get the message from the user in the buffer and print it
8. Now first user types the message and its written in the socket
9. If write operation was not successful then print the error message
10. The first user waits for message from the second user.if second user types exit th~n chatting session stops else go back to step 7.