跳转至

5.0 Network Layer

The Network Layer is a fundamental concept in computer networks, residing above the Data Link Layer and below the Transport Layer in the OSI model.

Layer Comparison and Relationships

LayerPrimary FocusScopeKey ProtocolsAddressing
Data Link LayerFrame transmission across single linkLocal (point-to-point)Ethernet, PPPMAC addresses
Network LayerPacket delivery across multiple networksEnd-to-endIP, ICMPIP addresses
Transport LayerReliable/unreliable data transferEnd-to-endTCP, UDPPort numbers

1. Role and Responsibilities * The primary role of the Network Layer is to get packets from a source host to a destination host. This is a crucial distinction from the Data Link Layer, which is typically concerned with transmitting frames across a single link. * It is the lowest OSI layer that has to deal with end-to-end transmission across interconnected networks. Layers above it, like the Transport Layer, also deal with end-to-end communication. * The Network Layer must cater for packets traveling across multiple networks, which may be different in technology, number, type, and topology (e.g., combining Ethernet, Token Ring, fiber optics, satellite networks). * Key design objectives for an effective Network Layer include being independent of processor/communication technology, independent of the number, type, and topology of the subnets, and providing a uniform addressing scheme for all hosts in the network.

2. Internet Protocol (IP) * IP is the main network layer protocol. It is most widely used, typically paired with TCP (Transport Control Protocol). * IP runs on all hosts and routers in the network. * It is responsible for handling the addressing and forwarding mechanisms. * IP relays data across network boundaries and delivers packets from one host to another using IP addresses.

3. IP Service Model (Focus on IPv4)

Service Characteristics Comparison

AspectIPv4 CharacteristicsImplications
Connection TypeConnectionless (datagram-based)No connection establishment required
Delivery GuaranteeBest-effort (unreliable)Packets may be lost, duplicated, delayed
OrderingNo guaranteePackets may arrive out of order
Error RecoveryNone at IP levelHigher layers (TCP) handle reliability
  • The service model provided by IP (specifically IPv4) is connectionless (datagram-based). This means a connection is not established beforehand; packets (datagrams) are simply sent out with destination information.
  • It provides best-effort delivery, meaning it is an unreliable service.
  • Due to this unreliable nature, packets may be lost, delivered out of order, duplicated, or delayed for a long time.
  • Despite being unreliable, this best-effort service is still useful in many scenarios.

4. IPv4 Addressing

Address Structure and Classes

ClassFirst BitsNetwork BitsHost BitsAddress RangeMax NetworksMax Hosts per Network
A08241.0.0.0 - 126.255.255.25512616, 777, 214
B101616128.0.0.0 - 191.255.255.25516, 38465, 534
C110248192.0.0.0 - 223.255.255.2552, 097, 152254
  • IP provides a uniform addressing scheme for all hosts, acting as a way of naming nodes.
  • IPv4 addresses are 32 bits (4 bytes) long. They are commonly written in dotted decimal notation, where each byte is represented as a decimal number between 0 and 255, separated by dots (e.g., 192.168.1.1).
  • IPv4 addresses have a basic hierarchical structure, consisting of a network part and a host part. This is analogous to a postal address structure like country, city, street, and house number.
  • IPv4 Address Classes (A, B, C) were historically used, where the class and the default split between network and host parts were determined by the first few bits of the address.
    • Class A: First bit is 0. Network part is the first 8 bits. Host part is the remaining 24 bits.
    • Class B: First two bits are 10. Network part is the first 16 bits. Host part is the remaining 16 bits.
    • Class C: First three bits are 110. Network part is the first 24 bits. Host part is the remaining 8 bits.

Special Addresses

Address TypeDescriptionExample (Class C)Usable for Hosts
Network AddressAll host bits = 0192.168.1.0No
Broadcast AddressAll host bits = 1192.168.1.255No
Host AddressesMixed host bits192.168.1.1 - 192.168.1.254Yes
  • Within any network or subnet, there are special addresses: the network address (all host bits are 0) and the broadcast address (all host bits are 1).
  • These two special addresses reduce the number of usable host addresses in a network or subnet. If a network/subnet has H bits for the host part, the number of usable host addresses is 2H - 2.
  • An IP address assigned to a device connected to the internet must be unique on the internet. They can be assigned dynamically (e.g., when connecting to a network like UniFi).

5. Subnetting (CIDR Basics)

Subnetting Example Calculation

Scenario: An ISP has been allocated 192.168.1.0/24 and needs to create 4 subnets.

SubnetNetwork AddressSubnet MaskCIDRUsable RangeBroadcast
1192.168.1.0255.255.255.192/26192.168.1.1 - 192.168.1.62192.168.1.63
2192.168.1.64255.255.255.192/26192.168.1.65 - 192.168.1.126192.168.1.127
3192.168.1.128255.255.255.192/26192.168.1.129 - 192.168.1.190192.168.1.191
4192.168.1.192255.255.255.192/26192.168.1.193 - 192.168.1.254192.168.1.255

Calculation Process: * Original network: 192.168.1.0/24 (8 host bits) * For 4 subnets: Need 2 additional bits (2² = 4) * New subnet mask: /26 (24 + 2 = 26 network bits) * Host bits per subnet: 6 bits (32 - 26 = 6) * Hosts per subnet: 2⁶ - 2 = 62 usable addresses

Subnet Mask Formats

CIDR NotationDotted DecimalBinary (last octet)Host BitsMax Hosts
/24255.255.255.0000000008254
/25255.255.255.128100000007126
/26255.255.255.19211000000662
/27255.255.255.22411100000530
/28255.255.255.24011110000414
  • Subnetting is a technique used to divide a larger network into smaller, distinct subnetworks. This is useful, for example, for an Internet Service Provider (ISP) to manage address space efficiently and distribute addresses to different customers or regions.
  • Subnetting is implemented using a subnet mask. The subnet mask is a 32-bit number, often written in dotted decimal notation or using slash notation (CIDR - Classless Interdomain Routing).
  • In the binary representation of a subnet mask, the bits that are part of the network/subnet address are set to 1, and the bits that are part of the host address are set to 0. The ones always fill from the left (most significant bit) to the right.
  • The slash notation (e.g., /24, /25) indicates the number of bits set to 1 in the subnet mask.
  • To determine if a destination IP address is on the same subnet as the sending host, the host performs a bitwise AND operation between its own subnet mask and the destination IP address. If the result equals the subnet number of the sending host, the destination is on the same subnet.

6. IPv4 Header

IPv4 Header Field Analysis

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  IHL  |Type of Service|          Total Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Identification        |Flags|      Fragment Offset    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Time to Live |    Protocol   |         Header Checksum       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Source Address                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Destination Address                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options                    |    Padding    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Key Header Fields Comparison

FieldSize (bits)PurposeKey ValuesImpact of Errors
Version4IP version identifier4 (IPv4)Wrong protocol processing
Header Length4Header size in 32-bit words5-15 (20-60 bytes)Parsing errors
Total Length16Entire packet size20-65535 bytesTruncation/buffer issues
TTL8Hop limit1-255Routing loops prevention
Protocol8Upper layer protocol1(ICMP), 6(TCP), 17(UDP)Wrong demultiplexing
Header Checksum16Error detectionCalculated valueCorruption detection

Fragmentation Control Fields

FieldPurposeValuesFragment Handling
IdentificationGroup fragments0-65535Same ID for all fragments of original packet
DF FlagDon't Fragment0/1If 1, packet must not be fragmented
MF FlagMore Fragments0/11 for all fragments except last
Fragment OffsetPosition in original0-8191 (×8 bytes)Reassembly order indicator
  • Every IP packet (datagram) carries an IPv4 header appended to the data payload from the upper layer. The header contains information needed to transfer the packet.
  • Understanding the fields in the IPv4 header is important. Key fields include:
    • Version: Indicates the IP version (e.g., 4 for IPv4). (IPv6 exists but is excluded from the exam).
    • Header Length: Specifies the length of the IP header in 32-bit units. A value greater than 5 implies the presence of the optional "Options" field.
    • Total Length: The total length of the IP datagram (header + data).
    • Identification: A value used to identify fragments belonging to the same original datagram.
    • Flags: Contains control bits related to fragmentation, including "Don't Fragment" (DF) and "More Fragments" (MF) flags. The DF flag set to 1 tells routers not to fragment the packet.
    • Fragment Offset: Indicates the position of a fragment relative to the beginning of the original unfragmented datagram. It is measured in units of 8 bytes.
    • Time To Live (TTL): A value that is decremented by each router (hop) the packet traverses. Its purpose is to limit the lifetime of a packet and prevent it from circulating endlessly in the network (e.g., due to routing loops). If TTL reaches zero, the packet is discarded.
    • Protocol Identifier: Indicates the protocol used by the upper layer (e.g., TCP (6), UDP (17), ICMP (1)).
    • Header Checksum: A checksum calculated only over the IP header. Its purpose is to detect errors in the header and ensure that routing information is correct. If due to error, the source or destination address changes, the packet would be misrouted.
    • Source IP Address: The 32-bit IP address of the sending host.
    • Destination IP Address: The 32-bit IP address of the intended receiving host.
    • Options and Padding: Optional fields that can extend the header.

7. Fragmentation and Reassembly

Fragmentation Example

Original Packet: 3000 bytes data + 20 bytes header = 3020 bytes total MTU Constraint: 1500 bytes

FragmentData SizeTotal SizeIdentificationMF FlagFragment OffsetOffset (bytes)
11480 bytes1500 bytes12345100
21480 bytes1500 bytes1234511851480
340 bytes60 bytes1234503702960

Calculation Notes: * Fragment Offset = (Byte Offset) / 8 * Fragment 1: 0 / 8 = 0 * Fragment 2: 1480 / 8 = 185 * Fragment 3: 2960 / 8 = 370

Fragmentation vs. Reassembly Comparison

AspectFragmentationReassembly
LocationSource host or intermediate routersDestination host only
TriggerPacket size > MTUReceiving fragments
Fields UsedID, DF, MF, Fragment OffsetID, MF, Fragment Offset
Error HandlingDrop if DF=1 and size > MTUDiscard all if one fragment lost
Performance ImpactProcessing overheadBuffer management, timeout
  • Messages may need to be divided into smaller packets (fragments) before transmission. This happens when a datagram is larger than the Maximum Transmission Unit (MTU) of the next network link it needs to traverse.
  • Fragmentation typically occurs at the source host or at intermediate routers if necessary.
  • The Identification, Flags (MF), and Fragment Offset fields in the IP header are used to manage fragmentation.
  • The "More Fragments" (MF) flag is set to 1 for all fragments except the last one. The "Fragment Offset" indicates the position of the fragment's data within the original datagram.
  • Fragments are reassembled back into the original datagram at the destination host. They are put together based on their Identification and Fragment Offset values, even if they arrive out of order.
  • IP itself does not provide recovery for lost fragments. If a fragment is lost, the entire original datagram cannot be reassembled, and a higher layer protocol (like TCP) would be responsible for requesting retransmission.
  • Sources generally try to avoid fragmentation due to the overhead involved. Re-fragmentation of an already fragmented packet is possible.

8. Forwarding (vs Routing)

Forwarding vs. Routing Comparison

AspectForwardingRouting
ScopeLocal router actionNetwork-wide process
FunctionMove packet input → output portCalculate/build forwarding tables
TimelinePer-packet basisPeriodic or topology-change triggered
Data StructureUses existing forwarding tableCreates/updates forwarding table
LocationIndividual routerNetwork control plane
Speed RequirementVery fast (hardware-based)Can be slower (software-based)

Example Forwarding Table

Destination NetworkNext HopInterfaceMetric
192.168.1.0/24Directeth00
192.168.2.0/2410.0.0.1eth11
0.0.0.0/010.0.0.254eth110
  • Forwarding is the local action taken by a router to move a packet from an input interface to an output interface.
  • A router determines the appropriate output port by looking up the destination IP address of the incoming packet in its forwarding table.
  • (While related, the process of creating or calculating these forwarding/routing tables is called Routing, which is an excluded topic).

Concept Integration and Relationships

Network Layer Process Flow

Source Host                Router                 Destination Host
     |                        |                           |
1. Create IP packet      2. Receive packet         6. Receive packet
   - Add IP header          - Check TTL               - Verify header
   - Fragment if needed     - Decrement TTL           - Reassemble fragments
     |                      - Check destination        - Extract payload
2. Send to router          - Lookup forwarding table      |
     |                      - Forward to next hop    7. Deliver to upper layer
     |                           |                        |
     +------ Network Path -------+                        |

Common Calculation Types

1. Address Class Identification * Given: 172.16.5.10 * Binary: 10101100.00010000.00000101.00001010 * First two bits: 10 → Class B

2. Subnetting Calculations * Network: 192.168.1.0/24, need 6 subnets * Required subnet bits: ceil(log₂(6)) = 3 bits * New mask: /27 (24 + 3) * Hosts per subnet: 2⁵ - 2 = 30

3. Fragmentation Calculations * Original: 4000 bytes, MTU: 1500 bytes * Fragments needed: ceil(4000/1480) = 3 * Fragment offsets: 0, 185, 370

These notes cover the examinable aspects of the Network Layer and IP based on the provided sources and your list of exclusions. Remember to provide clear explanations and justifications for your answers in the exam.