Networking All-in-One For Dummies. Doug Lowe
Чтение книги онлайн.
Читать онлайн книгу Networking All-in-One For Dummies - Doug Lowe страница 33
It’s also important to know that, at least at this level of operation of the switch, the switch has no idea or concern for the contents of the Ethernet frame’s payload. In particular, the switch is not concerned with the possibility that the payload may be an IP packet, which in turn contains an IP address. Switching does not rely on or even know about IP addresses. Switching is a layer-2 function, and layer 2 is concerned with MAC addresses. IP addresses are a layer-3 concern and, thus, are hidden from switches.
Here’s where I have to tell you that I lied. It isn’t exactly true that switches don’t care about IP addresses. Many advanced switches have layer-3 features that do look at the IP address. But when they do, they’re acting more like routers than switches. Routers work at layer 3 and, therefore, deal with IP addresses. I have more to say about that later in this chapter, in the “Understanding Routers” section.
So, to recap, when a switch receives a packet on one of its ports, the switch looks in the Ethernet frame to determine the destination MAC address. The switch then looks that address up in its MAC address table, determines which port is associated with the destination address, and forwards the packet on to that port.
Which begs the question: What happens if the switch doesn’t recognize the destination MAC address in the forwarding database? The answer is found in the next section.
Flooding
When a switch receives a packet that is intended for a MAC address that isn’t in the switch’s internal MAC address table, the switch has no way to know what port to forward the packet to. In that case, the switch has no option but to revert to acting like a hub: The switch simply forwards the packet on all available ports other than the one the packet arrived on, of course. This is called flooding, which is the third function of a switch (the first two being learning and forwarding).
The packet will be forwarded even to ports for which the switch has already learned a MAC address. This is necessary because a single port can be a pathway to more than one MAC address, as is the case when the port is connected to another switch.
Flooding is similar to broadcasting, but it isn’t quite the same. A broadcast packet is a packet that is intended for every recipient on the network. Thus, a switch must forward broadcast packets to every port. In contrast, flooding results when the packet has a single destination, but the switch doesn’t know how to reach it. Thus, the switch sends the packet to every port in the hopes that one of them will lead to the destination.
Hopefully, flooding doesn’t happen too often. There’s a very good chance that the destination device will receive the packet and send a reply back to the sender. In that case, the switch will record the MAC address of the recipient in its table. Then, the next time a packet intended for that destination is reached, the switch will be able to forward it to the correct port rather than flood the network again.
Looking Deeper into Switches
In the previous sections, you learned about the three basic functions of a switch:
Learning: The switch learns what devices are reachable on each of its ports.
Forwarding: The switch forwards incoming packets just to the correct port based on the intended destination.
Flooding: The switch forwards incoming packets to all ports when it hasn’t yet learned how to reach the intended destination.
In the following sections, I dig deeper into the operation of switches to explain more about how they operate.
Collision domains
One of the main benefits of switches over hubs is that switches minimize the frequency of collisions on the network. Consider a four-port switch in which Computers 1, 2, 3, and 4 are connected to ports 1, 2, 3, and 4. If port 1 receives a packet from Computer 1 that is intended for Computer 2, the switch will forward the packet to port 2. If, at the same time, port 3 receives a packet intended for Computer 4, the switch will forward that packet to port 4. Both of these packets can travel on the network at the same time because at no time will they exist on the same set of network interfaces or cables. Thus, the packets will never collide.
In contrast, if these four computers were connected with a hub, the packets would collide because the two packets would be forwarded to all the ports, not just the ports connected to the destination computers.
This reduction of collisions is so fundamental to what a switch does that a common definition of what a switch is reads like this: A switch is a device that divides collision domains. A collision domain is a segment of a network on which collisions are possible. In an old-style Ethernet network built with hubs, the entire network is a single collision domain because all the network interfaces that connect to the network will see all packets that travel on the network. But when a switch is used, the network is divided into separate collision domains.
In a switched network, each collision domain consists of just two network interfaces: the port on the switch and the port on the destination device (typically a computer, but possibly another switch). An eight-port switch divides a single collision domain with eight devices into eight separate collision domains, each with only two devices.
Switches don’t completely eliminate collisions. For example, suppose a switch has received a packet intended for a computer, and that computer attempts to send a packet at the same moment that the switch attempts to forward the received packet to the computer. In that case, the two packets collide, and both the switch and the computer must wait and try again a bit later.
Bridging
A bridge is a device that is very similar to a switch, but it typically has fewer ports — perhaps as few as two. The primary purpose of a bridge is to provide a link between two networks, so some bridges have just two ports. Like a switch, a bridge examines the destination MAC address of every packet it receives and forwards the packet to the other side of the bridge only if the bridge knows that the destination is on the other side.
Technically speaking, a switch is simply a multiport repeaters bridge. The distinction is mostly a historical one, because bridges were invented and widely used before switches. Before switches became inexpensive, large Ethernet networks used multiple hubs to connect computers and other devices, and a few bridges would be introduced into the network to break up large collision domains. Now that switches are common, you don’t see separate bridging devices much anymore.
However, one function that a bridge can perform can come in handy: A bridge can be used to connect two different types of networks. For example, suppose your main network uses Cat-5e cable, but you also have a smaller network that uses fiber-optic cable. You can use a bridge to link these two types of networks. The bridge would have two ports: One Cat-5e port and one fiber-optic port. When the bridge receives a packet on the Cat-5e port, it forwards it to the fiber-optic port, and vice versa.
All switches can perform this type of bridging to connect Cat-5e devices that operate at different speeds. For example, most computers have network interfaces that operate at 1 gigabit per second (Gbps). But many printers have slower, 100 megabits per second (Mbps) connections. The ports on a switch can automatically detect the speed of the device on the other end of the cable, so you can plug a 1 Gbps computer or a 100 Mbps