The Data Link Layer
Today we are going to start discussing layer 2, residing above layer 1 and below layer 3.
Layer 2 interact with layer 3 (network layer), taking packets and delivering it to layer 2 and layer 2 will do its magic on it, and from then on it will pass its link to the physical layer, which will do its modulation and multiplexing. So, what is layer 2 responsible for? Layer 3 has added source IP address, Destination IP, along other things. Layer 2 will add its own header, including another error detection field. There is another reason that layer 2 will add its own detection.
When layer 2 thinks about creating the frame, with some characteristics (aka air channel), and it wants to delivers the unit to the next hop. I'm not thinking long term, layer 2 only thinks about delivering a unit with the help of the physical layer (layer 1) to the next hub. Layer 3, on the other hard, doesn't care which channel is being used. Layer 3 wants to deliver a packet to its destination, and that's with the help of intermediate routers. It may do changes, if there is a problem it may drop a packet. The error detection in Layer 2 will be checked by the next hop in Layer 2. We try to limit redundancy by making checksum in Layer 2 to the checksum in Layer 3.
Even if we have error detection in layer 2 and layer 3 they may or may not be independent of each other. Layer 2 may add error detection or direction. Layer 2 can also communicate to the next node. If I'm going to aim to connect to the next node, what is it do I need to do? There may be others that are listening to the same chat (Wi-Fi) and you are sending your frame to the access point. There might be other devices overhearing your communication. As part of the header, I need to figure out who the intended next hub is. To identify, there must be something that I can identify along the next parts. MAC address is used to identify next hub. Each device is measured as a MAC address. Maybe later on we can talk about some detail about layer 3 and we will each each layer has an IP address. The size and range of MAC address will depend on nature of the layer. I need to identify "Who's my next node" by providing that corresponding MAC address. Layer 2 relies on MAC addresses to identify the next hub.
What if we had a shared channel? If I send at the same time, what's going to happen to our friend, they will overlap with each other and since we're using the same layer 2 technology, we are talking at the same frequency, we get a collision. What do we do about that then? We need to somehow coordinate so that when I speak, you don't speak. The protocols in both are linear access protocols. Layer 2 accepts a packet from network layer and transmits it affectively to the next hop over one communication channel (JUST ONE).
Media access protocols may enable a frequency channel to be used by other devices and try to see if someone else is transmitting their waves. What is it that I need to do to aim just to the next Hub? There may be others that are listening to the same chart. There may be other devices that can overhead your communication. As part of the header, I have to identify who the intended next hub is. Each interface has a MAC address and size of the MAC address will depend solely on the size of the layer. Shared channels, I need to identify the next hub by providing the MAC address. Each layer has source and destination MAC address so the next hub will know where it is. Layer 2 relies on MAC addresses to identify what the next hub is.
The second thing that the Layer 2 would introduce is Addressing, helping identify the next hub. How do we deal with collisions? We need to somehow coordinate so that when I speak, you don't speak, and the protocols thar are involved are called Media Access Protocols. You can point some similarities between these protocols. Media access protocols are more dynamic in nature, you want them to be careful. I can also do encryption and security protocols aiming for signing the content or encrypting the content, also may be done in layer 2. The contents of the packets will be encrypted so that your bank will know that you specifically are speaking to them. Security in layer 2 would be intended just to protect this one hop. Layer.
Framing allows the physical layer to know the beginning and end of a packet and it's important for correct modulation. Addressing provides the next hop information (MAC Address) in frames. It's necessary for shared channels such as the ethernet. Between 2 nodes trying to communicate, the frames that are considered over this channel may be unacknowledged. There are cases in which I want you to acknowledge my frame. In Ethernet, you send a frame and you don't wait for an acknowledgement. Connection oriented service is layer 2 connects sequence layers because these sequences are related to each other. Some service are connections, acknowledged, and unacknowledged. Layer 2 also performs error detection and correction.
There are cases where layer 2 will have a flow control protocol, regulating the traffic rate to prevent a fast sender from outpacing a slow receiver. There are hardware implementations of layer 2 as network interface cards. However, flow control is now mostly in transport layer (or layer 3, 4, 5) etc. But layer 2 focuses over next hub.
Layer 2 also handles media access, when the channel is shared along multiple devices, resolving contention when multiple users are sharing the same communication channel. There's also a plot background with layer 2 receiving packet from the network layer. Layer 2 could take the packet as one unit, and it's going to frame it and add its own header. Some things in the header will be error detection. Eventually the frame will go to physical layer which will do multiplexing and then modulation. Here is the diagram.
There is a difference between doing functions in layer 2 vs layer 3 and above. This article will mainly focus on framing and addressing. Think about 2 devices, and layer 3 has a packet to be sent. The packet is destined for somewhere on the internet, but the next hop in relation to the layer 2. When a packet comes to layer 2, it's going to add both a header and a trailer. The payload itself is going to be the packet. Layer 2 is going to send the frame into the physical layer (modulation) and the physical layer of the next hub will demodulate. Then we will identify the beginning and the end of the frame, and once it identifies, it takes the payload out and layer 2 will pass the packet onto layer 3. It's just that the physical layer of machine one is talking to the physical layer of machine 2.
The header and trailer fields contain information inserted by Layer 2 itself to accomplish its own responsibilities with source and destination MAC addresses as well as error detection and correction, start and end frame delimiters, etc. The payload would contain the packet from layer 3.
Once it identifies the frame it takes the payload out (from layer 3). If we have media access protocol, the layer 2 will keep track of what packets are being sent and transmitted. Let's talk about how framing is done. With byte count, frame begins with a count of the number of bytes in it. First byte is the byte count and then a frame. Problem is that if you get an error in the first frame it will mess everything up. The error happens if the first byte of the frame doesn't correspond well. You typically don't have a frame with 5 bytes, but there are cases where you have a very small frame with a few bytes. An example of a setup needing a smaller frame is. It's difficult to resynchronize after an error.
Byte stuffing relies on special flags, a few bytes that are special. When you have a flag inside a frame, layer 2 will add an escape character so the next hub will know. Basically you have a flag at the beginning of the field and flag at the end, then escape character (to escape bytes). Just like you add escape before the flag, if you got an escape as data, put an escape before it. Occurrences of the flags in the data must be escaped. Whenever 2 escapes come out, one of them is taken out.
In bit stuffing, Frame flag has 6 consecutive 1's (01111110 or 0x7E). Whenever you see 6 's you should follow it in by 0. The advantage here is you don't add extra bytes, you add bits to make the size of the frame not change a lot and this works when there is a lot of running number of the same number (lots of running 1's).
Ethernet and 802.11 use a combination of techniques, relying on a preamble (flag) but has a still longer sequence. It also has a byte count (flag would be used to figure out what is the beginning and the end). If the preamble is seen by the receiver and the byte count tells you something else, there would be a problem. So there is a preamble (72 bits) for beginning of frame and byte count toe locate the end of the frame. If they both confirm, then the byte count is correct.
Possible services are unacknowledged connectionless service is where frame is sent with no connection or error recovery. An example is Ethernet. A second is Acknowledged connectionless service, where frame is sent with retransmissions if needed, and example is Wi-Fi. Then acknowledged connection oriented service where connection is set up and we need frame sequence numbers to ensure that the packets are delivered in order.

Comments
Post a Comment