February 15, 2014

What is the difference between Switching and Routing?

This is often one of the questions asked by budding network engineers. If you have noticed the title, I asked What is the difference between 'Switching and Routing' and not 'Routing and Switching'. Does it matter? Not much. But that is the logical order in which networks work. First Switch and then Route.

First, let us start with switching. If I have five computers and need them to be networked, so that they can share information, the simplest thing I can do is to buy a switch and connect them to the switch ports though an Ethernet cable. Then simply turn the switch 'on' and the magic begins. All five computers are now able to  communicate with each other, provided you have correctly configured the computers to use the network (such as IP address, subnet mask etc.). You now got a LAN going!

So, how does this work? When a computer application such as web browser or e-mail client want to send information to another computer, such as a web-server or e-mail server, they use IP addresses to identify/address each other. But to actually send a frame from one host to another host, we need MAC address.

The computes talk to each other using the MAC addresses on a LAN. As long as the IP addresses of all the five computers belong the same IP Subnet (on a typical LAN usually they are), they will be able to find the MAC addresses of the destination computer to which they want to communicate. Yes, you guessed it right, it is the ARP (Address Resolution Protocol) that helps a sending host to find the MAC address of the destination host. Once the sending host knows the MAC address of the destination host, it can simply send the frame to the switch, of course, with its own MAC address as the Source MAC address and the destination host's MAC (learnt via ARP) as the destination MAC address in the frame header.

Now, the switch is an intelligent device that knows where (to which switch port) to forward the frame to, based on the destination MAC address found in the frame header. The switch learns this information by simply listening to the incoming frames and associating the source MAC address of the incoming frame to the incoming port. The switch maintains this table of information.

So, the bottom line is, as long as the sending host and receiving host are on the same LAN, they communicate with each other (by the way of switch switching the frames) using their MAC addresses.

But in real life, the sending and receiving hosts need not be on the same LAN. Say, the web-browser is located on your home LAN and the web-server (say www.google.com) is located somewhere on the Google's LAN. One way to make the web-browser to communicate with the web-server is to put them on the same LAN (as discussed above), but in this scenario, it is not going to happen unless you have a switch that is big enough to reach from your house to Google :)

So, what do we do? We Route.

If the sending host and the receiving host are on different LANs, we obviously need to send the packets from one LAN to the other. This is called routing. For this we need a router. Router is a network device that interconnects LANs and forwards packets between LANs. A router has one interface on each, on the LANs it interconnects.

If the destination IP is on a different LAN (i.e., on a different IP Subnet), you need to switch the frame from the sending host to the router(gateway). Remember, the sending host and the router interface are on the same LAN, so we switch from sending host to router. The router routes the packet (based on the destination IP address) to the next-hop router. Here again, the frame is switched from gateway router to the next-hop router. The next-hop router routes the frame towards the final destination in a similar way.

In summary;

Source Host ----------> Gateway Router : Switch
At the Gateway Router: Route
Gateway Router ---------------> Next-hop router: Switch
At the next-hop Router: Route
Next-hop Router--------------> Next Next-hop router: Switch
and so on until the last router is reached
At the last router: Route
Last Router ----------------> Destination host: Switch

We switch within the LAN, we route across the LAN.

I hope that was useful. This is my first blog. Will soon add some pictures to this.

Please leave a comment.

Thank you.




1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Please feel free to leave your comments here: