the working principle of the Three Musketeers
1. Hub
1. What is a hub
Before you know a hub, you must know a repeater. In the network we come into contact with, the simplest thing is that two computers form a "dual-computer interconnection" through two network cards, and the unshielded twisted pair is generally used as the signal line between the two network cards. Because the signal power of twisted pair will gradually decay when transmitting signals, when the signal decays to a certain extent, it will cause signal distortion, so the maximum transmission distance of twisted pair is 1 meters on the premise of ensuring signal quality. When the distance between two computers is more than 1 meters, in order to realize the interconnection between the two computers, people install a "repeater" between the two computers, whose function is to sort out the signals that have been attenuated incompletely, regenerate the complete signals and then continue to transmit.
the repeater is the predecessor of the common hub, and the hub is actually a multi-port repeater. Generally, hubs have 4, 8, 16, 24, 32 RJ45 interfaces. Through these interfaces, hubs can complete the "relay" function for a corresponding number of computers. Because it is in a "central" position in the network, the Hub is also called "hub".
2. The working principle of the hub
The working principle of the hub is very simple. Take Figure 2 as an example, which is a hub with 8 ports and * * * connects 8 computers. The hub is in the center of the network, and the signals are forwarded through the hub, so that eight computers can be interconnected. The specific communication process is as follows: if computer 1 wants to send a message to computer 8, when the network card of computer 1 sends the message to the hub through twisted pair, the hub will not directly send the message to computer 8, but will "broadcast" the message to eight ports at the same time. When computers on eight ports receive this broadcast message, they will check the message. If they find that the message is addressed to themselves, they will receive it, otherwise they will ignore it. Because the information was sent by computer 1 to computer 8, eventually computer 8 will receive the information, while the other seven computers will not receive the information because it is not their own.
3. Features of the hub
1) * * Enjoy bandwidth
The bandwidth of the hub refers to the maximum speed it can reach when communicating. At present, there are mainly three kinds of hubs used in small and medium-sized local area networks on the market: 1Mbps, 1Mbps and 1/1Mbps adaptive.
the maximum transmission speed of a hub with 1mb bandwidth is 1Mbps. Even if the computer connected to it uses a 1Mbps network card, the data transmission speed is only 1Mbps. The 1/1Mbps adaptive hub can automatically adjust the bandwidth according to the speed of the network card connected to the port. When connected to the 1Mbps network card, its bandwidth is 1Mb;. When connected to a 1Mbps network card, its bandwidth is 1Mb, so this kind of hub is also called a "two-speed hub".
the hub is a "* * *" device, and the hub itself can't identify the destination address. When host A in the same local area network transmits data to host B, the data packet is transmitted by broadcasting on the hub-based network, and each terminal determines whether to receive it by verifying the address information of the data packet header.
because the hub can only transmit one set of information in a clock cycle, if a hub is connected with a large number of machines, and many machines often need to communicate at the same time, the work efficiency of the hub will be very poor, such as information blocking and collision.
why is this happening? For example, in Figure 2, when computer 1 is sending information to computer 8 through the hub, if computer 2 also wants to send information to computer 7 through the hub at this time, when it tries to contact the hub, it finds that the hub is busy with computer 1' s business, so computer 2 will "stand in front of the hub with data" and always ask the hub to stop the work of computer 1 to help itself. If computer 2 successfully "grabs" the hub (because the hub is "* * *", it is easy to grab it), the data of computer 1 in the transmission state will stop at this time, so computer 1 will also "grab" the hub ...
It can be seen that the real speed of each port on the hub is related to the bandwidth of the hub and the number of devices working at the same time. For example, eight computers are connected to a hub with a bandwidth of 1Mb. When these eight computers work at the same time, the real bandwidth of each computer is 1/8=1.25Mb!
2? Half-duplex
Let's talk about full-duplex: when two devices send and receive data, both parties can send or receive at the same time. This transmission mode is full-duplex. However, in the half-duplex transmission mode, when one device is sending data, the other device can only receive it, but not send its own data at the same time.
because the hub adopts the way of "broadcasting" to transmit information, the hub can only work in a half-duplex state when transmitting data. For example, computer 1 and computer 8 need to transmit some data to each other. When computer 1 is transmitting data, computer 8 can only receive the data sent by computer 1. Only when computer 1 stops transmitting and is ready for receiving can it send its own information to computer 1 or other computers.
2. Switch
1. What is a switch
A switch is also called a switched hub. It regenerates information and forwards it to a designated port after internal processing. It has automatic addressing ability and switching function. Because the switch sends each packet from the source port to the destination port independently according to the destination address of the transmitted packet, it avoids collision with other ports. A generalized switch is a device that completes the information exchange function in a communication system.
2. The working principle of the switch
In the computer network system, the switch is introduced for the weakness of the * * * enjoy working mode. Hub is the representative of * * * working mode. If the hub is compared to a postman, then the postman is a "fool" who can't read words-he doesn't know how to send the letter directly to the recipient according to the address on the letter, but will only distribute it to all people with the letter, and then let the recipient judge whether it is his own according to the address information! The switch is a "smart" postman-the switch has a high-bandwidth back bus and an internal switching matrix. All ports of the switch are hooked on this back bus. When the control circuit receives the data packet, the processing port will look up the address table in the memory to determine which port the NIC (network card) of the destination MAC (hardware address of the network card) is hooked on, and quickly transmit the data packet to the destination port through the internal switching matrix. If the destination MAC does not exist, the switch will broadcast to all ports. After receiving the port response, the switch will "learn" the new address and add it to the internal address table.
It can be seen that when a switch receives a "letter" sent by a network card, it will quickly deliver the letter to the recipient according to the address information above and the "permanent residence book" it has mastered. In case the address of the recipient is not in the "household register", the switch will distribute the letter to all people like a hub, and then find the recipient. After finding the recipient, the exchange will immediately register this person's information in the "household registration book", so that when serving the customer in the future, the letter can be delivered quickly.
3. Performance characteristics of the switch
1) Exclusive bandwidth
Because the switch can intelligently send data to the destination quickly according to the address information, it will not "disturb" those non-recipients when transmitting data like a hub. In this way, the switch can transmit data between multiple port groups at the same time. Moreover, each port can be regarded as an independent network segment, and the two communicating parties enjoy all the bandwidth independently without competing with other devices. For example, when host A sends data to host D, host B can send data to host C at the same time, and both transmissions enjoy the full bandwidth of the network-assuming that they use a 1Mb switch at this time, the total traffic of the switch at this time is equal to 2×1Mb=2Mb.
2) full duplex
when two ports on a switch are communicating, they can realize full duplex communication because the channels between them are relatively independent.
III. Differences between hubs and switches
From their working principles, switches and hubs are quite different. First of all, from the perspective of OSI architecture, hubs belong to the first layer physical layer equipment of OSI, while switches belong to the second layer data link layer equipment of OSI.
Secondly, from the working mode, the hub adopts a "broadcast" mode, so it is easy to produce a "broadcast storm", and the performance will be greatly affected when the network scale is large. When the switch works, only the requesting port and the destination port respond to each other without affecting other ports, so the switch can isolate the collision domain to some extent and effectively suppress the occurrence of "broadcast storm".
In addition, in terms of bandwidth, no matter how many ports there are in the hub, all ports share a bandwidth, and only two ports can transmit data at the same time, while other ports can only wait, and the hub can only work in half-duplex mode; For the switch, each port has an exclusive bandwidth, and when two ports work, it will not affect the work of other ports. At the same time, the switch can work not only in half-duplex mode but also in full-duplex mode.
if you describe the difference between a switch and a hub in the simplest language, it should be the difference between intelligence and non-intelligence. To put it bluntly, a hub is just a network device that connects multiple computers. It can only play the role of signal amplification and transmission, and cannot deal with the fragments in the signal, so it is easy to make mistakes in the transmission process. The switch can be regarded as an intelligent hub, which not only has all the characteristics of the hub, but also has the functions of automatic addressing, switching and processing. Moreover, in the process of data transmission, the sender and the receiver work independently and have no relationship with other ports, thus achieving the purpose of preventing data loss and improving throughput.
4. Routers
1. The role of routers
Through hubs or switches, we can form a relatively large local area network (Figure 3), but when the number of machines reaches a certain number, the problem comes: for a local area network composed of hubs, due to the "broadcast" working mode, when the network is large, information will collide and collide in the transmission process. Secondly, this kind of LAN is not safe and is not conducive to management.
in order to solve these problems, people divide a large network into small subnets and network segments, or directly divide them into multiple VLANs (virtual local area networks). In a VLAN, information sent by one host can only be sent to other hosts with the same VLAN number, and members of other VLANs cannot receive these information or broadcast frames. After using VLAN to divide the network, the broadcast storm on the network can be effectively suppressed, the security of the network can be increased, and the management and control can be centralized (Figure 4).
since it is a local area network, what should I do if hosts in different VLAN need to communicate with each other? At this time, you have to help through the Router (router). Routers can connect computers in different subnets, network segments and VLAN and let them communicate freely. In addition, we all know that there are many types of networks at present, and different networks use different protocols and speeds. When two networks with different structures need to be interconnected, they can also be realized through routers. Routers can connect two LAN segments with similar or different architectures to form a larger LAN or a WAN.
It can be seen that a router is a network device that connects multiple networks or segments. It can "translate" data information between different networks, segments or VLAN, so that they can "read" each other's data and form a larger network.
2. How the router works
The so-called routing refers to the activity of moving information from the source location to the target location through the interconnected network. So how exactly does the router translate? When we study and translate English at ordinary times, we will certainly prepare an English-Chinese dictionary, through which we can realize the co-occurrence conversion between English and Chinese. For the router, it also has this dictionary for translation-path table. Routing Table stores the related data of various transmission paths, such as the logo information of subnets, the number of routers on the network and the name of the next router. The path table can be fixed by the system administrator, dynamically modified by the system, automatically adjusted by the router or controlled by the host.
Routers can interconnect different subnets and network segments, so routers are different from hubs and switches. They are generally installed in the "backbone" of the network, instead of working at the grassroots level like hubs and switches. For example, a large-scale enterprise LAN, based on management, security and performance considerations, generally divides the whole network into multiple VLANs. As a result, when communicating between VLANs, routers must be used.
For this enterprise network, it definitely needs to be connected to the Internet. For enterprises, it is usually connected to the Internet by renting DDN lines of telecommunications or using ADSL, Cable and ISDN. At this time, due to the different network systems and protocols used, routers are also needed to complete the interconnection between the enterprise network and the Internet.
Click to enlarge
Generally speaking, during the routing process, information will pass through at least one or more intermediate nodes. Usually, people will compare routing and switching, mainly because in the eyes of ordinary users, their functions are exactly the same. In fact, the main difference between routing and switching is that switching takes place at the second layer (data link layer) of the OSI reference model, while routing takes place at the third layer, namely the network layer. This difference determines that routing and switching need to use different control information in the process of moving information, so the ways to realize their respective functions are different. Routers decide the forwarding of data through routing.