How Routing and Switching Work

in #technology6 years ago

The internet is a collection of routers that deliver packets from any source to their intended location. Here's some of how they work.

Switching

Switching uses simple rules, and as such is less capable than routing and is limited to local area networks and networks without loops. Loops are forbidden because the packets will circulate around the loop until it gets broken. Switching is what Layer 2 Ethernet networks use, and does not have to be IP packets.

Dumb Switch


There is only one thing that dumb switches do, and that is whenever it receives a packet on any interface, it sends a copy of that packet to every other port. This is a simple flood operation, so every station attached to a network of dumb switches will receive every packet sent by every other station. This rule will work even if it is inefficient and it doesn't require the switch to keep track of state information, so these switches are usually much cheaper than the alternatives.

Smart Switch


Smart switches are an improvement over dumb switches. The simplest smarts switch keeps track of which ports have which addresses, and then only sends packets to ports that have received a packet from the destination station in the past. To do this, the switch keeps track of all the source MAC addresses that a port receives in a MAC Address Table (the new entry is highlighed). In hardware, this is implemented as a Content Adressable Memory (CAM), and in software it can be implemented as a hash table.

Routing


Routing is a step up from switching, at Layer 2 with Internet Protocol, versions 4 and 6. Routers maintain a routing table that it uses to determine where to send packets depending on the destination address. Unlike switching networks, routers are able to handle loops and can have redundant network paths to a given endpoint.

It is not uncommon to have a switch built into a router. This switch is somewhat different however, because not all ports are on the same switching domain. These switching domains are called Virtual Local Area Networks (VLANs). To get a packet between VLANs, a router is used to move it to the next network. When this is done, the IP addresses are not modified, but the MAC addresses are. The source MAC address is changed to the MAC address of the router interface the packet is being sent down, and the destination MAC address is changed to the MAC address of the next hop.

Routing also requires information on where packets addressed to a particular address should be sent next. This is the routing table, and consists of the network address and a netmask, and information needed to send the packet to the next router or the VLAN if the network is directly attached to the router thru nothing except switches.

Each router has a its own route table. The table should contain as the next hop that is the adjacent router that is the closest to the destination address. This sets up a gradient where packets always move towards their final destination. In cases where routes are incorrect, and end up with loops, the IP packet has a field called Time To Live (TTL) that is reduced by one every time a router forwards a packet, and if the TTL field reaches zero, the packet is discarded.

The routing table may be populated in a number of ways. Static routes are manually added to the table. Dynamic routes can be added from an internal or external gateway protocol, the difference being internal gateway protocols are used entirely withing a single organization's network, while external gateway protocols are used between multiple organizations. Border Gateway Protocol (BGP) is the external gateway protocol that distributes routes for the internet today.

When the routers are setup correctly, packets can move between any two nodes in the network, in both directions. In this example, 10.0.0.2 sends a packet (green) to 192.168.0.2, which then responds with its own packet (red).

Resources

All resources for this post, including the source files for the diagrams, can be found here

Sort:  

Congratulations @teknomunk! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @teknomunk! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

You got your First payout

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!