BIT254 Network and Data Communications

Network and Data CommunicationsUnit 613 min read

Network Layer: IP Addressing & Routing Protocols

Unit 6 of Network and Data Communications: Explores how data is routed across networks via IP addressing, routing protocols (distance vector vs. link state), and real-world applications like eSewa transactions and Kathmandu traffic routing.

TAKEAWAYS:

  • IP addresses (IPv4/IPv6) uniquely identify devices on a network, structured hierarchically for scalability.
  • Routing protocols (e.g., RIP, OSPF) dynamically determine the best path for data packets using algorithms like Dijkstra’s.
  • Distance vector protocols (e.g., RIP) rely on periodic updates and suffer from slow convergence, while link-state protocols (e.g., OSPF) use flooding and shortest-path algorithms.
  • Subnetting divides networks into smaller subnets to optimize traffic flow and security (e.g., in Daraz’s order processing).
  • NAT (Network Address Translation) conserves IPv4 addresses by mapping private IPs to public ones (used in NTC’s ISP networks).
  • Routing tables store next-hop information, with metrics like hop count, bandwidth, and delay guiding packet forwarding.

1. Introduction to the Network Layer

The network layer (Layer 3 of the OSI model) handles logical addressing, routing, and packet forwarding across networks. It abstracts the underlying physical topology, enabling end-to-end communication between devices on different subnets or autonomous systems.

ApplicationDataTransportSegmentNetworkPacketData LinkFramePhysicalBits
OSI Model: The Network Layer (Layer 3) handles logical addressing, routing, and packet forwarding.

Key Functions

  • Logical Addressing: Assigns unique identifiers (IP addresses) to devices.
  • Routing: Determines the best path for data packets using routing protocols.
  • Packet Forwarding: Moves packets from source to destination via routers.
  • Congestion Control: Mitigates network overload (e.g., via QoS policies).

2. IP Addressing

IP addresses are 32-bit (IPv4) or 128-bit (IPv6) identifiers assigned to devices. They enable unicast, multicast, and broadcast communication.

08162431Network (192.168.1)24 bitsHost (100)8 bitsBinary8 bitsBinary8 bitsBinary8 bitsBinary8 bitsDecimal8 bitsDecimal8 bitsDecimal8 bitsDecimal8 bits
IPv4 Address Breakdown: 192.168.1.100/24 (Network: 192.168.1.0, Host: 100)

IPv4 Address Structure

An IPv4 address is divided into network and host portions using a subnet mask (e.g., 255.255.255.0 for /24). Example: 192.168.1.100/24

  • Network portion: 192.168.1
  • Host portion: 100
Bit Position Network (8 bits) Host (8 bits) Host (8 bits) Host (8 bits)
Binary 11000000 10101010 00000001 11001000
Decimal 192 168 1 100

IPv6 Addressing

  • 128-bit format (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).
  • Simplified notation: Omit leading zeros and consecutive zero groups (e.g., 2001:db8::8a2e:370:7334).
  • Advantages: Larger address space, built-in security (IPsec), and no NAT required.

Special IP Addresses

Type Example (IPv4) Purpose
Loopback 127.0.0.1 Testing local machine
Default Gateway 0.0.0.0 (default) Exit point for external networks
Broadcast 255.255.255.255 Sent to all devices on a subnet
Multicast 224.0.0.0–239.255.255.255 Sent to a group of devices
Private Ranges 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 Internal networks (NAT required for internet)

3. Subnetting and CIDR

Subnetting divides a network into smaller subnets to:

  • Reduce broadcast traffic.
  • Improve security (isolate segments).
  • Optimize routing.
graph TD
    A["192.168.1.0/24"] -->|"Subnet Mask: /26"| B["192.168.1.0/26"]
    A -->|"Subnet Mask: /26"| C["192.168.1.64/26"]
    B -->|"Hosts: 1-62"| D["192.168.1.1-192.168.1.62"]
    C -->|"Hosts: 65-126"| E["192.168.1.65-192.168.1.126"]

Subnet Mask Calculation

Given a network 192.168.1.0/24 and needing 64 hosts:

  • Required host bits: 6 (since ).
  • Subnet mask: /26 (32 – 6 = 26).
  • New subnet: 192.168.1.0/26 and 192.168.1.64/26.

Classless Inter-Domain Routing (CIDR)

  • Replaces classful addressing (A/B/C classes) with flexible prefix lengths (e.g., 192.168.1.0/24).
  • Example: 10.0.0.0/16 covers 10.0.0.0 to 10.255.255.255.

4. Network Address Translation (NAT)

NAT maps private IP addresses to a public IP, conserving IPv4 addresses. Example: A home network with 192.168.1.100 uses NAT to share a single public IP (e.g., 203.0.113.5).

A["Private Network (192.168.1.100)"] --> B["NAT Gateway (203.0.113.5)"] --> C["Internet"]


Types of NAT

Type Description
Static NAT Fixed mapping (e.g., server exposed to the internet).
Dynamic NAT Temporary mapping (e.g., home devices sharing a public IP).
Port Address Translation (PAT) Maps multiple private IPs to one public IP + port (e.g., 203.0.113.5:8080).

5. Routing Protocols

Routing protocols determine the best path for packets. They are classified into:

  • Interior Gateway Protocols (IGPs): Used within an autonomous system (e.g., RIP, OSPF).
  • Exterior Gateway Protocols (EGPs): Used between autonomous systems (e.g., BGP).

Distance Vector Routing (e.g., RIP)

  • How it works: Each router shares its routing table with neighbors periodically (e.g., every 30 seconds).
  • Metric: Hop count (maximum 15 hops).
  • Disadvantages:
    • Slow convergence (takes time to update routes).
    • Count-to-infinity problem (routes oscillate between infinite hops).
sequenceDiagram
    RouterA->>RouterB: "My route to D is 2 hops (via me)"
    RouterB->>RouterC: "My route to D is 3 hops (via RouterB)"
    RouterC->>RouterA: "My route to D is 4 hops (via RouterB)"

Example: In a network with routers A, B, and C, if the link between B and C fails, RIP may incorrectly route traffic indefinitely until the timeout expires.

  • How it works:
    1. Each router floods its link-state advertisements (LSAs) to all routers.
    2. Routers build a complete topology map.
    3. Dijkstra’s algorithm computes the shortest path.
  • Advantages:
    • Faster convergence (updates propagate quickly).
    • Supports hierarchical routing (areas).
  • Disadvantages:
    • Higher CPU/memory usage (storing topology maps).
    • Complexity in implementation.
stateDiagram-v2
    [*] --> RouterA: Flood LSA
    RouterA --> RouterB: Send LSA
    RouterB --> RouterC: Send LSA
    RouterC --> RouterA: Acknowledge
    RouterA --> [*]: Compute Shortest Path

Example: NTC’s ISP network uses OSPF to dynamically reroute traffic if a fiber link fails, ensuring minimal delay.


6. Routing Tables and Metrics

A routing table stores routes to destinations, including:

  • Destination IP: Target network.
  • Next Hop: Next router to forward to.
  • Interface: Outgoing interface.
  • Metric: Cost (e.g., hop count, bandwidth).

Example routing table entry:

Destination     Next Hop     Interface   Metric
192.168.2.0/24   192.168.1.2  eth0        1
0.0.0.0/0        203.0.113.1  eth1        1 (default gateway)

Routing Metrics

Metric Description
Hop Count Number of routers between source and destination (RIP).
Bandwidth Available throughput (e.g., 10 Mbps link is better than 1 Mbps).
Delay Propagation time (e.g., satellite links have higher delay).
Reliability Probability of link failure (e.g., fiber is more reliable than wireless).
Load Current traffic on a link (avoid congested paths).

7. Routing Algorithms

  1. Start from the source router.
  2. Update tentative distances to neighbors.
  3. Select the shortest path iteratively.
| Router | Distance | Next Hop |
|--------|----------|----------|
| A      | 0        | -        |
| B      | 3        | A        |
| C      | 5        | A        |
| D      | 8        | B        |

Bellman-Ford (Distance Vector)

  • Each router updates its table based on neighbors’ advertisements.
  • Formula: , where is the cost from Z to Y.

8. Hierarchical Routing

Large networks use hierarchical routing to simplify management:

  1. Core Layer: High-speed backbone (e.g., NTC’s national fiber network).
  2. Distribution Layer: Aggregates traffic (e.g., regional ISPs).
  3. Access Layer: Connects end devices (e.g., home routers).
A["End Devices"] --> B["Access Router"] --> C["Distribution Router"] --> D["Core Router"]

9. Routing in Autonomous Systems (BGP)

Border Gateway Protocol (BGP) routes traffic between autonomous systems (AS) (e.g., NTC, Ncell, ISPs).

  • Path Vector: Tracks the AS path to avoid loops.
  • Policy-Based: Uses business rules (e.g., prefer local ISPs).

Example BGP update:

UPDATE: NEXT_HOP=203.0.113.1, PATH=[AS1234, AS5678], MED=100

In the Real World

  1. eSewa Transactions:

    • Uses IP routing to forward payment requests from your phone to eSewa’s servers.
    • NAT ensures multiple users share a single public IP at the ISP (NTC/Ncell).
    • BGP routes traffic between eSewa’s data centers globally.
  2. Daraz Order Processing:

    • Orders from Kathmandu to Pokhara are routed via OSPF in Daraz’s network layer.
    • Subnetting isolates inventory databases (e.g., /24 for warehouses, /26 for checkout servers).
    • Load balancing (a QoS technique) ensures fast delivery of product pages.
  3. Kathmandu Traffic Routes:

    • Think of Kathmandu’s roads as a network layer:
    • IP addresses = unique vehicle IDs (e.g., KAT-1234).
    • Routers = traffic lights directing flow.
    • Link-state protocols = Google Maps recalculating routes in real-time when a road (link) fails.
    • Distance vector = old-school drivers asking, “How far to the next gas station?” and updating maps slowly.

Worked Example: IP Subnetting for a Bank Branch

Scenario: A bank branch in Pokhara has 50 workstations and needs to subnet its network 192.168.10.0/24.

  1. Calculate required subnets:

    • Hosts per subnet: (since usable hosts).
    • Subnet mask: /26 (32 – 6 = 26).
    • Subnets: 192.168.10.0/26, 192.168.10.64/26, etc.
  2. Assign subnets:

    • Subnet 1: 192.168.10.0/26 (hosts: 192.168.10.1 to 192.168.10.62).
    • Subnet 2: 192.168.10.64/26 (hosts: 192.168.10.65 to 192.168.10.126).
  3. Routing:

    • Routers use OSPF to exchange link-state updates.
    • If the link to the main server fails, OSPF recalculates paths in <1 second.

Comparison Table: Routing Protocols

Feature Distance Vector (RIP) Link-State (OSPF)
Update Mechanism Periodic (30 sec) On-link changes (flooding)
Convergence Time Slow (~30 sec) Fast (<1 sec)
Topology Knowledge Limited (neighbor info) Complete (full map)
Loop Prevention Count-to-infinity Dijkstra’s algorithm
Scalability Poor (hop limit = 15) Excellent (hierarchical)
CPU/Memory Low High
Example Use Case Small office networks ISPs, large enterprises

Exam Tip

  1. IP Addressing:

    • Always show binary-to-decimal conversion for IPv4 (e.g., 11000000.10101010 → 192.168).
    • For IPv6, simplify notation (e.g., 2001:db8::1).
    • Memorize private IP ranges and special addresses (loopback, broadcast).
  2. Subnetting:

    • Practice calculating subnet masks and usable host ranges.
    • Use the formula: for hosts (where = prefix length).
    • Draw network diagrams with subnets labeled.
  3. Routing Protocols:

    • Compare RIP vs. OSPF in a table (as above).
    • Explain Dijkstra’s algorithm with a small example (3–4 routers).
    • For BGP, mention AS paths and policy routing.
  4. Real-World Applications:

    • Link NAT to ISPs (NTC/Ncell) and subnetting to Daraz’s order systems.
    • Use traffic routing (Kathmandu roads) to explain link-state vs. distance vector.
  5. Common Pitfalls:

    • Avoid calling RIP “reliable” (it’s unreliable due to slow convergence).
    • Don’t confuse hop count with bandwidth as the only metric.
    • For subnetting, always subtract 2 for network/broadcast addresses.

[Router]
  - Input Ports (Ethernet/Wi-Fi)
  - CPU (Processes packets)
  - Forwarding Table (IP → Next Hop)
  - MAC Table (Local MAC → Port)
  - Output Ports (Uplink/Downlink)

Based on the TU BIT syllabus for Network and Data Communications (BIT254), unit 6.

Discussion

Loading…