Lab3 Omnet++

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Cairo University Computer Networks-1

Faculty of Engineering CMP405-A /CMPN405


Computer Department Fall 2021

Framing and Error detection


1 lab3
2 Lab Objectives

 Given a packet from the network layer ,


The data link layer should add the framing and the
error detection bits to it .
 In this lab, we will implement the character count
framing and the parity check bits for error detection.
3 Lab Objectives

 Say the payload input form network layer is ‘hi’.


 The output : ‘00000100 01101000 01101001 00000101’

Header Payload ‘h’ Payload ‘i’ Parity checks


(Ch_count) (even parity)
00000100 01101000 01101001 00000101
4 C++ Needed functions revision
1) cin/cout/string
 You have to write ‘std::’ before functions that belong to the std library in
the c++ files.
 You can use the cin and cout but it will out the results on the console
instead of inside the simulation.
 During simulation , you may need to press step in the simulation window
then return back to the editor window to access the console.
5 C++ Needed functions
1) cin/cout/string revision
 For example :
6 C++ Needed functions revision
1) cin/cout/string
 Use function string.size() // gets the size of the string.
 Remember that the string is just a character array, and each character is
one byte.
7 C++ Needed functions revision
2) bitset
 The bitset STL library is used to make operations on the bit level.
 You have to include it first inside the ‘.h’ file.
 #include <bitset>
 In the c++ you have to write std:: before the bitset definition.
 The bitset constructor can take characters, integers, strings ,…etc.
 It has much more functionalities but we will revise what we need.
8 C++ Needed functions revision
2) bitset
9 C++ Needed functions revision
2) bitset
 You can do bitwise operations as well .
10 C++ Needed functions revision
2) bitset
 Use bitset.to_string() to convert the binary stream to binary string.
 Use bitset.to_ulong() to convert the binary stream to unsigned integer.
 Use casting like (char) bitset.to_ulong() to convert the binary stream
to the asci character.
11 C++ Needed functions revision
3) vectors/iterators
 The vector STL library is used to construct easy and dynamic c++ arrays.
 The vector can store any type [ int , string ,bitset, ….etc. ]
 You have to include it first inside the ‘.h’ file.
 #include <vector>
 In the c++ you have to write std:: before the vector definition
12 C++ Needed functions revision
3) vectors/iterators
 You can loop on any vector by iterator of the same type of the vector

 The same applies for vector of bitset (s)


std::vector<std::bitset<8> > vec; [take care of the space > > ]
13 Lab3 requirement

 Design a simple network of two nodes called “sender” and “receiver”.


 The sender node takes the input string from the user “string of any length”.
 The sender node, will convert the string to it’s ASCI representation, add the
frame header “character count”, add the frame trailer “error detection byte”, and
send the bitstream to the receiver node.
 Before sending, the sender will have a 50% chance of introducing a single bit
error to any bit in the bitstream using the uniform random distribution .
14 Lab3 requirement

 The sender also has to print the bitstream before the single bit error and after it
if any, in the console in the following format.
message “hi” :
00000100
01101000
01101001
00000101

 You should also print which bit is modified.


15 Lab3 requirement

 The receiver node would check if there is any thing wrong in the received
bitstream, if there is error, it should print an error message.
 If the message is correct, the receiver will convert the message back to its
original string given from the user and print it like the following.
The original message is “hi”.
 You are not to make the sender send the “original string” obviously.
16 Lab3 requirement
helping notes
 You have to do XOR operation on all the payload characters to calculate the even
parity check bits. What is the easiest way to do this ?
 Before sending the message back we have to convert it to c-string as message name
is of type c-string, so what to do ?
 Convert each char to asci again using (char)bitset.to_ulong() .
 Append the characters to one string .
 Send the string as the message name.
 At the receiver side, do the reverse conversion again.
17

Thank You !!

You might also like