Layer 2 - Data Link Layer: Layer 2 is the domain of switches. You may not have a switch at home, but your PC at work certainly connects to one. The idea at Layer 2 is this: provide a software solution to address the physical layer devices, and provide a means of verifying that the physical signal is error free.
The most common method of implementing Layer 2 on the Internet is called Ethernet (that first "e" must be pronounced as a long e, as in "eat" or I will pounce on you...sorry, pet peeve of mine). With Ethernet, every device has a Media Access Control (MAC) address. In this manner, my computer's Network Interface Card (NIC; where the cable plugs into the computer) can address a message specifically to your computer's NIC if we are both on the same network. Without layer 2 addressing, if our two computers needed to talk to each other they would have to send a message to every computer on the network at once. In the meantime, those computers may be sending a message to everyone at once. It sounds like my family reunions, but it is a nightmare in the networking world. Layer two allows two device to have a quiet conversation with eachother without bother everyone else on the network.
Once devices are addressed, Ethernet at Layer 2 describes a means to pass the digital message to the physical wire or radio. This is done in an Ethernet frame; the frame is a specific pattern that must be followed to create a digital signal. The is a set length that the frame can be and there is a specific order of items that the frame contains. Included in this frame is the destination address, the source address, an identification of the type of frame it is (data, finally, Ethernet adds a Cyclical Redundancy Check (CRC) calculation to the end of each message that is passed to the physical layer; this CRC allows the remote device to verify if the message received is complete or corrupted compared to the message sent. I wish the English language had this feature built into it.
The most interesting thing at Layer 2, for me, is how it allows you to optimize and subdivide networks. Ethernet only allows one device to use the wire at a time. If two devices try to use the wire simultaneously, this is called a collision. If you have ever tried to merge onto a busy road, or get a word in edgewise among talkative people, you know how inefficient and frustrating it can be to have to wait your turn. Waiting your turn should be unnecessary in the computer world; everything should be instantaneous and perfectly efficient.
By using a switch, you can limit collisions. First, you make sure that there is only one device plugged into each port of the switch. That way, the only two devices on each wire are the switch and one other device (a PC, server, printer, router, another switch, etc...) By using Layer 2 MAC addresses, the switch can then determine which two ports to connect for each conversation. For instance: Assume that I am on Port 1 and the network printer is on Port 20. When I need to send a print job, I can do so immediately since the wire is dedicated to me. First, my PC uses Address Resolution Protocol (ARP) to discover the MAC address of the printer based on its known IP address (which is coming up in Layer 3). My PC then sends out an Ethernet frame onto the wire with my MAC address as the source and the printer's MAC address as the destination. The next device in the physical path, the switch, receives this frame on Port 1, reads the destination port, checks its list of known MAC Addresses per port (the CAM table) and forwards the frame to port 20.
Prior to the affordability and prevalence of switches, people often used hubs to connect a network together. With a hub, everyone is connected to everyone else automatically; you are all on the same wire, essentially. Therefore, if I try to download music on my computer while you are trying to send a print job, we will collide. Then, our PC's each wait a random interval before trying to use the wire again. In the meantime, either the wire is unused or someone else seizes the opportunity to check their email. The network is a lot slower. Imagine have 8 teenage girls in a house with one bathroom. Now imagine that same house with 9 bathrooms (to include a place for your hygiene). Which house would have fewer boyfriends waiting in the parlor?
A switch can be subdivided into VLANs. This subdivision is accomplished at layer 2. To connect VLANs, you need to move up to layer three. A switch has multiple ports, and normally every port has access to every other port on the switch. If you tell the switch that some ports should be in VLAN 1 and others in VLAN 2, then the switch will make sure that frames are not switched to ports from one VLAN to another. There are times when a device will broadcast a series of frames to every device on the network; by subdividing a switch into multiple VLANs, you make sure that broadcasts are not received by devices that are unrelated. Broadcasts take up time and bandwidth; therefore, the fewer broadcasts that each network experiences, the better. This is called creating a Broadcast Domain.
Layer 2 also ensures that the physical layer did not corrupt the frame during transmission. If a cable is experiencing excessive resistance which degrades the electrical signal, or if the signal is interfered with from Electrical Magnetic Frequency (EMF), the received frame may be quite different from what was transferred. Layer two adds a value to the end of the packet that is based on the numeric value of the data that is transmitted. The receiving device looks at the bits coming off the wire, adds up their numeric value, runs a calculation on that value, and then com[pares its answer to the value that was added by the transmitting device to the end of the frame. This is called a Cyclical Redundancy Check (CRC). It is a mathematical method of determining whether the data has been accurate received compared to what was transmitted.
How to "See" Layer 2 on your PC: You can see layer 2 on your Windows PC easily. First, click on the Start button, then the "Run" button. In the white text box, type "CMD". In the black box that pops-up here, type "ipconfig -all". Look for the line that says "Physical Address". That code is your MAC Address, in hexadecimal form.
To see more Layer 2, type "arp -a". This will show you all the MAC addresses that you PC knows about. Remember, MAC addresses remain local your network. Therefore, your PC will never know the MAC address of the Google server, nor does it need to. It only needs to know what the MAC address is of the router on your network that will take you to Google, which is probably the only thing in your ARP table right now. If you know the IP address of another device on your local network, such as a PC or printer, "ping" it and then do "arp -a" again. You will now see the MAC address of that device in your ARP table's output.
To sum up, Layer 2 provides addressing, collision avoidance, and error checking. The key concepts at Layer 2 that will further your knowledge are MAC Addresses, CRC, ARP, and VLANs. Understanding the importance and mechanics of collision and broadcast domains will help you grasp concepts of layers 2 and 3, as well as help you design efficient networks throughout your career.
No comments:
Post a Comment