So now let's have a look at layer 2 which is the link layer or the data link layer the main job of layer two is to organize that stream of ones and zeroes into frames into useful units of information and the way that layer two normally does that is by having a special pattern of ones and zeros that marks the start and the end of the frame this is a pattern which either cannot occur in the middle of a frame or is very unlikely to occur in the middle of a frame so that as the stream comes in it the receiver can see where a frame starts and where a frame ends that's the fundamental thing that layer 2 does now there are additional things that layer two can do depending on what networks technology you're using so some layer twos will detect transmission errors so they will detect whether a frame has been corrupted or not i'll show some examples of that in a moment some layer twos may support the idea of a shared medium so that is for example multiple devices on the same medium which could be multiple devices on the same ethernet or multiple devices on a wireless network now if you're going to be sending data between multiple devices you need some way of identifying which device should receive each frame so layer 2 can have its own addressing system so if you can identify where a frame is supposed to go that's unicast for meaning one destination or you may have a special address called a multicast or broadcast which means that this frame needs to go to multiple destinations or all of the destinations on your network layer 2 may also have some mechanism for doing access control in other words taking turns and who can use the medium and collision detection which is making sure that we can recover if two devices try to transmit at the same time again this was something that was used with hubs but nowadays the most important application for this is in wireless networks where it's important where the devices can take it in turns to transmit and usually layer 2 will also carry some information about what layer 3 protocol is being used and that allows you to mix multiple layer 3 protocols on the same network all right so let's have a look at some examples of layer 2. so the first example i'm going to show you is ppp the point-to-point protocol this used to be widely used in dial-up networks but is now still very very commonly used in broadband access networks like dsl networks so your data is encapsulated inside ppp frames and that ppp is your layer two protocol so your frame layer to pvp looks like this there's a flag which marks the start of the frame special pattern of bits there's a field that contains the protocol which is what layer 3 information is being carried then there's an information field that's the actual data that you want to carry then there is a crc a cyclic redundancy check which is used to detect transmission errors and then a flag at the end to indicate the end of the frame so the the crc the cyclic redundancy check is a pattern of bits which is calculated across the whole frame so the transmitter calculates that pattern and puts it into the into the frame sends the frame the receiver does the same calculation and sees if they get the same crc result now if they get a different crc it means that the data must have been corrupted somehow on the way and therefore the frame can be discarded it's better to throw away the whole frame than have a frame that has bad information in now as it happens pvp has a bunch of other features as well which are useful in broadband access networks so for example there are sub protocols one's called lcp where the two ends of a pvp link can agree the parameters for that link there's authentication so the users can be required to log in provide a username and password before they gain access and there are facilities for negotiating layer 3 settings which basically means assigning an isp can assign an ip address to the end user these are just extra features that are part of ppp the fundamental thing is it's a layer two protocol it divides up into frames now let's have a look at another one this is ethernet very very important and very common so an ethernet frame looks like this it starts with a preamble it has a header and in the header we have a destination mac address and a source mac address now these are the media access control addresses that identify each ethernet device a mac address is a 48-bit number and it's programmed into the network card by the manufacturer so in principle all network cards in the world should have unique mac addresses doesn't always happen sometimes vendors don't do it properly but most of the time this is this is true so in the header you have a source and destination mac address and you have also a protocol field that identifies what the layer 3 protocol is and then you have information and the crc so this looks very much like the ppp frame the difference is we now have these destination and source mac addresses and that's because ethernet is an access network with multiple devices on the same network whereas ppp is point to point there's there's a device at one end and there's a device at the other end and those are the only two devices involved in in ppp ethernet also uses this preamble at the start of the frame to do carrier sense and collision detection so specifically in the old ethernets with hubs that's period of time was used to detect whether somebody else was transmitting at the same time so what kind of equipment do we get at layer 2 well the equipment is called either a switch or a bridge and those terms mean the same thing they mean something that works at layer two some people will use a switch to mean a physical piece of hardware and a bridge to mean a software switch but they're doing the same thing the way that a switch works is it receives an entire layer 2 frame and then selectively re-transmits that frame so unlike a layer 1 device which would receive a bit at a time and send that on layer 2 will receive the whole layer 2 frame and then re-transmit it afterwards as part of its operation a switch will learn which mac address belongs to which port or where it can find each mac address in the network which port it has to send to get to that device and in that case if it knows that a particular mac address is on a particular port then it will only resend the frame on that port there's no need to resend it on any of the other ports because that's not where the device you're interested in is so if it knows that then it can restrict the sending to one port if it doesn't know where the mac address is then it has to fall back to the same behavior as a hub and send it out through all the ports and just hope that it reaches the destination now our special frames called broadcast frames in ethernet they have a special mac address that identifies them as a broadcast frame and in that case the frame has to be sent out of all ports just like on a hub and when a switch is working on a packet it only looks at the layer 2 header it doesn't look at anything inside the rest of the of the frame
© Produced by Philip Smith and the Network Startup Resource Center, through the University of Oregon.
Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
This is a human-readable summary of (and not a substitute for) the license. Disclaimer. You are free to: Share — copy and redistribute the material in any medium or format Adapt — remix, transform, and build upon the material The licensor cannot revoke these freedoms as long as you follow the license terms. Under the following terms: Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. NonCommercial — You may not use the material for commercial purposes. No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.