# Switching Techniques

![[Pasted image 20250126203838.png]]Switching techniques are methods used in telecommunications to transfer data between devices across a network. These techniques ensure efficient communication by managing data flow, routing, and bandwidth allocation. The three primary types are **Circuit Switching**, **Packet Switching**, and **Message Switching**.

## 1. Circuit Switching

### Definition:

A dedicated and continuous communication path is established between two nodes (source and destination) for the entire duration of a communication session, ensuring exclusive use of resources.

### Use:

Primarily used in traditional telephone networks and real-time applications requiring constant bandwidth, such as voice calls or video conferencing.

### Pros:

- **Consistent Quality**: Fixed bandwidth allocation ensures a stable and predictable communication quality without interruptions.
    
- **Low Latency After Setup**: Once the circuit is established, there is minimal delay during data transmission, making it suitable for time-sensitive communication.
    

### Cons:

- **Inefficient Utilization of bandwidth**: Resources remain allocated even during idle periods, leading to underutilization of bandwidth.
    
- **Setup Time**: Establishing the connection requires time before communication can begin, which may delay data transmission.
    
- **Scalability Issues**: Limited number of simultaneous connections due to fixed and dedicated resource allocation.
    

### Working:

1. A physical communication path is reserved between the sender and receiver.
    
2. Data flows continuously along the reserved path in a steady stream.
    
3. Once the session is complete, the connection is terminated, releasing the resources.
    

---

## 2. Packet Switching

### Definition:

Data is divided into smaller units called packets, each of which is transmitted independently across the network using shared resources. Packets may take different routes and are reassembled at the destination. Makes use of store and forward technique, where the packets are stored in a buffer on all the nodes and then forwarded.

### Use:

Widely used in computer networks, such as the Internet, email systems, and video streaming platforms.

### Pros:

- **Efficient Bandwidth Utilization**: Bandwidth is dynamically shared among multiple users, maximizing resource usage.
    
- **Fault Tolerance**: Packets can be rerouted around failures or congested nodes, ensuring robust communication.
    
- **Scalability**: Supports a large number of connections efficiently without the need for dedicated resources.
    

### Cons:

- **Variable Latency**: Congestion and network dynamics can cause unpredictable delays, making it less ideal for real-time applications.
    
- **Packet Reordering**: Packets may arrive out of sequence, requiring additional processing to reassemble them in the correct order.
    
- **Overhead**: Each packet requires header information (such as source, destination, and sequence number), which reduces the effective payload size.
### Working:

1. Data is broken into packets, each containing a portion of the original message along with control information.
    
2. Packets are independently routed through the network to the destination.
    
3. At the destination, packets are reassembled in the correct sequence to reconstruct the original data.
    

### Subtypes:

- **Datagram Packet Switching**:
    
    - **Definition**: Each packet is treated as an independent unit with no predetermined path.
        
    - **Keywords**: Dynamic routing, flexible path selection, stateless communication.
        
    - **Pros**:
        
        - High flexibility, allowing packets to take any available route.
            
        - Resilient to network failures and congestion.
            
    - **Cons**:
        
        - Increased complexity in reassembling packets due to variable paths.
            
        - Potential for variable delays and out-of-order delivery, requiring additional error handling.
            
- **Virtual Circuit Switching**:
    
    - **Definition**: A logical path is established before packet transmission, maintaining an ordered flow of packets.
        
    - **Keywords**: Logical connection, predictable sequence, session-oriented.
        
    - **Pros**:
        
        - Ensures packets arrive in order, simplifying reassembly at the destination.
            
        - More predictable performance compared to datagram switching, especially under stable network conditions.
         
        - Dynamic rerouting in case of congestion 
        
    - **Cons**:
        
        - Initial setup time required for establishing the logical path.
            
        - Less adaptable to sudden path failures compared to datagram switching.
            

---

## 3. Message Switching

### Definition:

Entire messages are transmitted from the source to the destination through intermediate nodes using the store-and-forward technique. Each intermediate node temporarily stores the message before forwarding it to the next.

### Use:

Historically used in telegraphy and early computer networks for non-real-time communication.

### Pros:

- **No Dedicated Path Required**: Eliminates the need for resource reservation, optimizing resource utilization.
    
- **Efficient for Long Messages**: Suitable for applications where the entire message must be delivered intact, such as file transfers.
    

### Cons:

- **High Latency**: Messages are stored and forwarded at each node, introducing significant delays.
    
- **Storage Requirements**: Intermediate nodes require large buffer space to hold entire messages.
    
- **Incompatibility with Real-Time Needs**: Unsuitable for applications requiring instantaneous communication, such as live streaming.
    

### Working:

1. The source sends the entire message to the first intermediate node.
    
2. The intermediate node temporarily stores the message, checks for errors, and forwards it to the next node.
    
3. This process continues until the message reaches its destination, where it is fully delivered.
    

---

These switching techniques form the backbone of modern communication systems, each tailored to specific needs based on their characteristics and operational mechanisms.

## Difference Between Datagram and Virtual Circuit Switching:

| **Aspect**           | **Datagram Switching**                                                              | **Virtual Circuit Switching**                                                     |
| -------------------- | ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| **Path**             | Packets are routed independently with no predetermined path.                        | A logical path is established before data transmission begins.                    |
| **Flexibility**      | Highly flexible as packets can take any available route.                            | Less flexible as all packets follow the predefined logical path.                  |
| **Order of Packets** | Packets may arrive out of order, requiring reordering.                              | Packets always arrive in sequence, simplifying reassembly.                        |
| **Setup Time**       | No setup time is required before transmission.                                      | Requires setup time to establish the virtual circuit before data transfer.        |
| **Adaptability**     | Resilient to network failures as packets can dynamically reroute.                   | Less adaptable to failures; path failures may require reestablishing the circuit. |
| **Latency**          | May experience variable latency due to dynamic routing and congestion.              | Offers more predictable latency once the virtual circuit is established.          |
| **Overhead**         | Higher overhead due to the need for independent routing information in each packet. | Lower overhead as routing information is shared across packets in the same path.  |


# Function of a Switch and a Bridge

## 1. **Switch**
A switch is a networking device that operates at the **data link layer (Layer 2)** of the OSI model. Its primary function is to connect multiple devices within a local area network (LAN) and facilitate efficient communication by forwarding data only to the intended recipient(s).

### Key Functions of a Switch:
1. **MAC Address Learning**:
   - Switches maintain a **MAC address table** (or CAM table) that maps each device's MAC address to the corresponding physical port.
   - When a device sends data for the first time, the switch records the MAC address and associates it with the port.

2. **Frame Forwarding**:
   - Switches examine the destination MAC address of each frame and forward it only to the specific port where the intended device is connected.
   - This reduces unnecessary network traffic, unlike hubs, which broadcast data to all devices.

3. **Full-Duplex Communication**:
   - Switches allow simultaneous sending and receiving of data on the same port, improving network efficiency and reducing collisions.

4. **Broadcast and Multicast Handling**:
   - Switches support broadcasting (to all devices) and multicasting (to specific groups of devices) for certain types of network communication.

5. **Segmentation and Collision Avoidance**:
   - By dividing the network into smaller segments, switches minimize collision domains, which increases overall network performance.


Switches require the **Spanning Tree Protocol (STP)** or its variations (like RSTP or MSTP) to prevent **network loops** in Layer 2 networks, which can cause severe disruptions in communication. Let’s break this down:

---

### **Why Network Loops Are a Problem**

In a switched Ethernet network, loops can occur if there are redundant paths between switches. While redundancy is important for fault tolerance, it can lead to:

1. **Broadcast Storms**:
    
    - Broadcast frames (like ARP requests) are forwarded out of all switch ports except the one they arrived on.
    - In a looped network, these frames circulate endlessly, consuming all available bandwidth and overwhelming the network.
2. **MAC Address Table Instability**:
    
    - Switches use MAC address tables to forward frames. In a looped network, a frame might be received on multiple ports, causing the switch to repeatedly update its MAC table with conflicting information.
    - This leads to improper forwarding of frames, disrupting communication.
3. **Duplicate Frames**:
    
    - Loops can cause the same frame to be delivered multiple times to the destination, leading to confusion and errors in communication.
---

## 2. **Bridge**
A bridge is a simpler networking device that also operates at the **data link layer (Layer 2)**. It is primarily used to connect two or more LAN segments and regulate traffic between them.

### Key Functions of a Bridge:
1. **Filtering Traffic**:
   - Bridges filter traffic based on MAC addresses to ensure only relevant data is forwarded between segments.
   - They reduce unnecessary traffic, helping to isolate and manage data flow between different parts of a network.

2. **Collision Domain Isolation**:
   - By separating network segments, bridges help reduce the size of collision domains, improving efficiency.

3. **Learning and Forwarding**:
   - Similar to switches, bridges maintain a **MAC address table** to learn which devices are connected to each segment.
   - They use this table to decide whether to forward or block a data frame.

4. **Broadcast Forwarding**:
   - Bridges forward broadcast frames to all segments of the network, as they do not have the advanced filtering capabilities of switches.

5. **Extending Network Size**:
   - Bridges are used to extend the physical size of a network by linking multiple LANs together.

---


# Router vs Gateway

| Feature                 | Router                                                                                   | Gateway                                                                                                                         |
| ----------------------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| **Definition**          | A device that connects multiple networks and routes data packets between them.           | A device that acts as an entry and exit point for data to/from different networks or systems.                                   |
| **Function**            | Focuses on determining the best path for forwarding packets to their destination.        | Acts as a translator between different network protocols, formats, or systems.                                                  |
| **Layer of Operation**  | Operates primarily at **Layer 3 (Network Layer)** of the OSI model.                      | Operates at multiple layers of the OSI model, depending on the type of gateway (e.g., Layer 3, Layer 4).                        |
| **Protocol Support**    | Works with specific network protocols, such as TCP/IP, to forward packets.               | Converts or translates protocols between networks (e.g., IP to IPX, HTTP to MQTT).                                              |
| **Primary Use Case**    | Used to connect different networks, such as LAN to WAN.                                  | Used for protocol conversion or bridging networks with incompatible architectures.                                              |
| **Address Translation** | Performs NAT (Network Address Translation) to enable private-to-public IP communication. | Handles protocol-level translation or data format conversions.                                                                  |
| **Traffic Handling**    | Routes packets based on IP addresses and routing tables.                                 | Processes data at a higher level, ensuring compatibility between networks or applications by doing translations and formatting. |
| **Complexity**          | Simpler compared to a gateway as it only handles routing decisions.                      | More complex due to protocol conversion and higher-layer functionality.                                                         |
| **Examples**            | Home routers, enterprise routers, or routing software (e.g., Cisco Routers, MikroTik).   | VoIP gateways, payment gateways, cloud gateways (e.g., AWS API Gateway).                                                        |

---

# Router vs Switch

| Feature                   | Router                                                                                                     | Switch                                                                                             |
| ------------------------- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| **Definition**            | A networking device that routes packets between different networks based on IP addresses.                  | A device that connects devices within a single network and forwards frames based on MAC addresses. |
| **Function**              | Routes traffic between different networks (e.g., LAN to WAN).                                              | Facilitates communication between devices in the same network (e.g., LAN).                         |
| **Layer of Operation**    | Operates at **Layer 3 (Network Layer)** of the OSI model.                                                  | Operates at **Layer 2 (Data Link Layer)**, though Layer 3 switches also exist.                     |
| **Addressing**            | Uses IP addresses to forward packets.                                                                      | Uses MAC addresses to forward frames.                                                              |
| **Primary Use Case**      | Connects and manages traffic between multiple networks, such as connecting a home network to the internet. | Connects devices within a single local area network (LAN).                                         |
| **Traffic Handling**      | Determines the best path for data to travel across multiple networks.                                      | Filters and forwards frames within a single network segment.                                       |
| **Broadcast Domains**     | Divides broadcast domains (each interface is its own broadcast domain).                                    | By default, does not divide broadcast domains but can do so with VLANs.                            |
| **NAT Support**           | Performs Network Address Translation to enable private IPs to communicate over public networks.            | Does not perform NAT.                                                                              |
| **Routing Capability**    | Supports routing protocols (e.g., RIP, OSPF, BGP) for dynamic path determination.                          | Does not support routing but forwards frames based on MAC tables.                                  |
| **Layer 3 Functionality** | Includes Layer 3 intelligence to make routing decisions.                                                   | Layer 2 switches lack Layer 3 functionality, but Layer 3 switches add basic routing capabilities.  |
| **Examples**              | Cisco routers, MikroTik, TP-Link routers.                                                                  | Cisco Catalyst switches, Netgear switches.                                                         |
