Latest update Android YouTube

Routing & Switching | Computer Networks: From Scratch to Mastery

Estimated read time: 64 min

Chapter 6: Routing & Switching

Mastering the protocols and technologies that direct traffic across networks, from routing algorithms to VLAN segmentation.

 PostImage | IndinTechnoEra

Introduction

Routing and switching form the backbone of modern network communication. Building on our understanding of IP addressing (Chapter 4) and network protocols (Chapter 5), this chapter explores how data is efficiently directed across networks.

By the end of this chapter, you will understand:

  • Key routing algorithms (RIP, OSPF, BGP) and their operation
  • VLANs for network segmentation and MAC address fundamentals
  • Switching techniques (Store & Forward vs Cut-through)
  • Static versus dynamic routing approaches
  • Routing table structure and function
  • Spanning Tree Protocol for loop prevention
  • Quality of Service (QoS) mechanisms

Routing Algorithms

RIP (Routing Information Protocol)

RIP is a distance-vector routing protocol that uses hop count as its metric. Key characteristics:

  • Maximum hop count of 15 (16 = infinity/unreachable)
  • Updates routing tables every 30 seconds
  • Uses Bellman-Ford algorithm
  • Simple to configure but slow convergence

RIP Version 2 Configuration (Cisco IOS)

Router(config)# router rip
Router(config-router)# version 2
Router(config-router)# network 192.168.1.0
Router(config-router)# no auto-summary

Common issues with RIP:

  • Count-to-infinity problem (solved with split horizon)
  • Slow convergence in large networks
  • Lack of support for VLSM in RIPv1

OSPF (Open Shortest Path First)

OSPF is a link-state routing protocol that uses Dijkstra's algorithm to calculate the shortest path. Key features:

  • Uses cost as metric (based on link bandwidth)
  • Fast convergence with triggered updates
  • Supports hierarchical design with areas
  • Requires more CPU/memory than RIP but scales better

OSPF Areas

  • Backbone Area (Area 0): Connects all other areas
  • Regular Areas: Connect to backbone via ABRs
  • Stub Areas: Don't receive external routes

OSPF Configuration (Cisco IOS)

Router(config)# router ospf 1
Router(config-router)# network 10.0.0.0 0.255.255.255 area 0

BGP (Border Gateway Protocol)

BGP is the path-vector protocol that routes traffic between autonomous systems (AS) on the internet. Key aspects:

  • Makes routing decisions based on paths, network policies, and rules
  • Uses TCP port 179 for reliable communication
  • Very scalable but complex to configure
  • Primary protocol for internet backbone routing

BGP Peering Configuration

Router(config)# router bgp 65001
Router(config-router)# neighbor 203.0.113.1 remote-as 65002
Router(config-router)# network 192.0.2.0

VLANs and MAC Addresses

Virtual LANs (VLANs)

VLANs logically segment networks at Layer 2, providing:

  • Improved security through isolation
  • Better performance by limiting broadcast domains
  • Simplified network management

VLAN tagging (IEEE 802.1Q) adds a 4-byte tag to Ethernet frames:

  • 12-bit VLAN ID (supports 4094 VLANs)
  • 3-bit priority field for QoS
  • Native VLAN (untagged traffic)

VLAN Configuration (Cisco IOS)

Switch(config)# vlan 10
Switch(config-vlan)# name Sales
Switch(config)# interface fastEthernet 0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10

Common VLAN Issues

  • VLAN mismatch on trunk links
  • Native VLAN configuration errors
  • Missing VLANs on some switches

Troubleshoot with: show vlan brief, show interfaces trunk

MAC Addresses

MAC (Media Access Control) addresses are 48-bit hardware addresses assigned to network interfaces. Key points:

  • First 24 bits: OUI (Organizationally Unique Identifier)
  • Last 24 bits: Device-specific identifier
  • Represented in hexadecimal (e.g., 00:1A:2B:3C:4D:5E)
  • Used for Layer 2 frame delivery

MAC Address Table

Switches maintain a MAC address table that maps MAC addresses to switch ports:

Switch# show mac address-table
          Mac Address Table
-------------------------------------------
Vlan    Mac Address       Type        Ports
----    -----------       ----        -----
 10    001a.2b3c.4d5e    DYNAMIC     Fa0/1

MAC Address Learning

  1. Switch receives frame on a port
  2. Notes source MAC address and port
  3. Adds entry to MAC address table
  4. Forwards frame based on destination MAC

Switching Techniques

Store & Forward

The switch:

  • Receives the entire frame before forwarding
  • Performs CRC error checking
  • Discards frames with errors
  • Higher latency but more reliable

Best for: Networks where reliability is critical

Cut-through

The switch:

  • Begins forwarding after reading destination MAC
  • Doesn't store entire frame
  • No error checking
  • Lower latency but may forward bad frames

Best for: High-performance, low-latency networks

Comparison Table

Feature Store & Forward Cut-through
Latency Higher Lower
Error Checking Yes No
Memory Usage More Less
Frame Size Stores entire frame Only reads header

Static vs Dynamic Routing

Static Routing

Manually configured routes:

  • Simple to implement
  • No protocol overhead
  • Requires manual updates
  • Doesn't adapt to topology changes

Configuration Example

Router(config)# ip route 192.168.2.0 255.255.255.0 10.0.0.2

Dynamic Routing

Routes learned via routing protocols:

  • Adapts to network changes
  • More complex to configure
  • Protocol overhead
  • Automatic updates

When to Use

Large networks, changing topologies, redundant paths

Choosing Between Static and Dynamic

  • Use static routing for small networks with simple topologies
  • Use dynamic routing for large networks with multiple paths
  • Hybrid approach: Static for edge routes, dynamic for core

Routing Tables

Routing tables contain the information routers use to forward packets. Key fields:

  • Destination Network: IP address and subnet mask
  • Next Hop: IP address of next router
  • Interface: Outgoing interface
  • Metric: Cost to reach destination
  • Route Source: How route was learned (static, RIP, OSPF, etc.)

Sample Routing Table (Cisco IOS)

Router# show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF

O    192.168.2.0/24 [110/20] via 10.0.0.2, FastEthernet0/1
C    192.168.1.0/24 is directly connected, FastEthernet0/0
S    203.0.113.0/24 [1/0] via 198.51.100.1

Route Selection Process

  1. Longest prefix match (most specific route)
  2. Lowest administrative distance
  3. Lowest metric

Administrative Distance

  • Directly connected: 0
  • Static route: 1
  • OSPF: 110
  • RIP: 120

Spanning Tree Protocol (STP)

STP (IEEE 802.1D) prevents loops in switched networks by:

  • Electing a root bridge
  • Calculating shortest paths to root
  • Blocking redundant paths

STP Port States

  • Blocking: No forwarding, listens to BPDUs
  • Listening: Prepares to forward but doesn't learn MACs
  • Learning: Learns MAC addresses but doesn't forward
  • Forwarding: Normal operation

Root Bridge Election

  1. Compare Bridge IDs (Priority + MAC address)
  2. Lower Bridge ID wins
  3. Default priority: 32768

Force a root bridge:

Switch(config)# spanning-tree vlan 1 root primary

STP Topology Visualization

Diagram showing root bridge, designated ports, and blocked ports in a switched network.

STP Variants

  • RSTP (802.1w): Rapid Spanning Tree - faster convergence
  • MSTP (802.1s): Multiple Spanning Tree - maps VLANs to instances
  • PVST+: Per-VLAN Spanning Tree (Cisco proprietary)

Quality of Service (QoS)

QoS mechanisms prioritize network traffic to ensure performance for critical applications:

Classification

Identify traffic types (e.g., VoIP, video, data) using:

  • DSCP (Differentiated Services Code Point)
  • 802.1p priority bits
  • ACLs

Queuing

Manage how packets are buffered:

  • Priority Queuing (PQ)
  • Weighted Fair Queuing (WFQ)
  • Class-Based WFQ (CBWFQ)

Policing/Shaping

Control bandwidth usage:

  • Policing: Drops excess traffic
  • Shaping: Buffers excess traffic

QoS Configuration Example (VoIP Priority)

Switch(config)# class-map match-any VOICE
Switch(config-cmap)# match dscp ef
Switch(config-cmap)# match ip rtp 16384 16383
Switch(config)# policy-map QOS-POLICY
Switch(config-pmap)# class VOICE
Switch(config-pmap-c)# priority percent 30
Switch(config)# interface FastEthernet0/1
Switch(config-if)# service-policy output QOS-POLICY

Practical Examples

Example 1: Configuring OSPF in Packet Tracer

Step-by-step guide to setting up a multi-area OSPF network:

Steps:

  1. Add three routers and connect them (serial or Ethernet links)
  2. Configure IP addresses on all interfaces
  3. Enable OSPF on each router:
    Router(config)# router ospf 1
    Router(config-router)# network 10.0.0.0 0.255.255.255 area 0
    Router(config-router)# network 192.168.1.0 0.0.0.255 area 1
  4. Verify OSPF neighbors:
    Router# show ip ospf neighbor
  5. Check routing tables to confirm OSPF routes

Troubleshooting Tips

  • Verify interfaces are up/up with show ip interface brief
  • Check OSPF is enabled on correct networks
  • Ensure area configurations match on connected routers
  • Use debug ip ospf events for detailed troubleshooting

Example 2: Visualizing OSPF Network with HTML Canvas

Interactive diagram showing an OSPF network with areas:

Interactive diagram showing routers in different OSPF areas with link costs.

OSPF Network Components

  • Backbone Router: In Area 0, connects to other areas
  • Area Border Router (ABR): Connects Area 0 to other areas
  • Internal Router: All interfaces in same area
  • Designated Router (DR): Elected on multi-access networks

Summary

In this chapter, we've explored the core concepts of routing and switching:

  • Routing Protocols: RIP (distance-vector), OSPF (link-state), BGP (path-vector)
  • VLANs: Logical segmentation at Layer 2 using 802.1Q tagging
  • Switching: Store & Forward (reliable) vs Cut-through (low latency)
  • Routing Methods: Static (manual) vs Dynamic (protocol-based)
  • Routing Tables: Contain destination networks, next hops, and metrics
  • STP: Prevents loops by blocking redundant paths
  • QoS: Prioritizes critical traffic through classification and queuing

Key Takeaways

  • Choose routing protocols based on network size and requirements
  • Use VLANs to improve security and performance
  • Understand how switches make forwarding decisions
  • Implement STP to prevent switching loops
  • Configure QoS for voice and video traffic

Further Reading

  • Books:
    • "Routing TCP/IP, Volume 1" by Jeff Doyle
    • "LAN Switching and Wireless" by Cisco Networking Academy
  • RFCs:
    • RFC 1058: RIP Version 1
    • RFC 2328: OSPF Version 2
    • RFC 4271: BGP-4
    • IEEE 802.1Q: VLAN Tagging
  • Online Resources:
    • Cisco's OSPF Configuration Guide
    • IEEE 802.1D Standard Documentation
    • Packet Tracer tutorials on Cisco Networking Academy

Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.