Network Layer and IPv4 Addressing
In questa pagina 5
In questa pagina 3
What the network layer does
The network layer sits above the link layer and below the transport layer (ISO-OSI Model and TCP-IP StackCommunication between two computers is too varied a problem (signals, errors, medium access, routing, flow control, data representation) for a single protocol, so it is divided into layers. The ISO/OSI model has 7 layers (physical, data link, network, transport, session, presentation, application); the TCP/IP stack merges the top three into one application layer, so it has 5. Each layer offers a service to the one above and talks only to its peer layer through PDUs; going down a header (PCI) is added: encapsulation. Addresses: MAC (link, local), IP (network, global), port (transport).ISO-OSI Model and TCP-IP Stack →). Its job is host-to-host delivery of datagrams across many different links, so its protocol runs in every router, not only in end hosts (the transport layer lives only in hosts: Transport Layer - Ports and MultiplexingThe transport layer provides logical end-to-end communication between application processes on different hosts and exists only in end hosts; the network layer delivers to the right computer (IP address) and transport to the right process (16-bit port number, 0 to 65535); an IP address plus a port is a socket and the four-tuple of IPs and ports identifies a connection, with multiplexing and demultiplexing done by UDP on the destination socket and by TCP on the whole four-tuple, and the protocols are UDP (connectionless, unreliable), TCP (connection-oriented, reliable) and SCTP.Transport Layer - Ports and Multiplexing →).
Three services:
- Encapsulation (framing). The sender adds a header (PCI) with source and destination network addresses to the segment received from transport; the receiver strips it. Routers read the addresses but never change them.
- Routing. Finding the best path; done by routing protocols that build the tables (Routing Algorithms - Link State and Distance VectorRouting finds least-cost paths in a weighted graph where routers are nodes and networks between routers are edges. Link state floods each router's local links (LSPs) so every router knows the whole graph and runs Dijkstra; distance vector has each router exchange its distance vector with neighbours only and update it with Bellman-Ford, D(A,w)=min(D(A,w), D(A,Y)+d(Y,w)), which converges in at most n-1 rounds but suffers from count to infinity (limited infinity of 16, hold down, triggered updates, split horizon, poison reverse); path vector announces whole paths, chooses by policy and detects loops by finding itself in the path.Routing Algorithms - Link State and Distance Vector →).
- Forwarding. On arrival of a packet the router reads the destination address, consults the forwarding table and picks the output interface (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →).
Error, flow and congestion control are left to upper layers (the only exception is security, via IPSec), to keep the network layer simple.
Protocols of the Internet network layer: IPv4 (packaging, forwarding, delivery: IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →), ICMP (error and query messages: ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →), IGMP (multicast management), ARP (IP to MAC translation: ARP - Address Resolution ProtocolTo place an IP datagram in a frame a node needs the MAC address of the next hop, obtained with ARP: a broadcast request (destination MAC FF:FF:FF:FF:FF:FF, carrying the sender's IP and MAC and the wanted IP) and a unicast reply with the wanted MAC, stored in the ARP cache; ARP always resolves the next hop (destination host or router), never the final destination, and since broadcasts do not leave the subnet a router can answer with its own MAC (proxy ARP).ARP - Address Resolution Protocol →).
The same host has three identifiers, one per layer: its name (application layer, resolved by DNS: DNS - Domain Name SystemDNS translates names such as www.amazon.com into IP addresses; it is a distributed hierarchical database (an inverted tree of up to 128 levels, with 13 root servers and domains registered through ICANN-accredited registrars), each ISP has a local DNS whose address the host gets from DHCP, the host asks it (usually over UDP) and it queries root, top-level and organisation servers, every server caches what it learns marking answers as non-authoritative until the TTL expires, records are (name, type, value, class, TTL), with NAT the DNS must return the public address, and there are four types of attack including cache poisoning.DNS - Domain Name System →), its IP address (network layer) and its MAC address (link layer, found by ARP).
The IPv4 address
Definition. An IPv4 address is a 32-bit number identifying the connection of a device to the Internet (not the device: a router with three interfaces has three addresses). It is unique and universal. It is written in dotted-decimal notation: four bytes, each written as a number from 0 to 255.
Example. is , because , , , .
There are addresses. In general bits give values and values need bits: this relation is used throughout subnetting.
Prefix and suffix
The first bits are the prefix (NetID), identifying the network; the other bits are the suffix (HostID), identifying the host inside it. Nodes in the same network share the NetID. Example with : in the NetID is and the HostID is .
Classful addressing (obsolete)
In the early Internet the prefix had a fixed length chosen among , recognisable from the first bits:
| class | first bits | first byte | networks | hosts per network | |
|---|---|---|---|---|---|
| A | 0 | 0 - 127 | 8 | (126 usable) | |
| B | 10 | 128 - 191 | 16 | ||
| C | 110 | 192 - 223 | 24 | ||
| D | 1110 | 224 - 239 | multicast | ||
| E | 1111 | 240 - 255 | reserved |
Shares of the space: A 50%, B 25%, C 12.5%, D and E 6.25% each. The scheme was abandoned because addresses were being exhausted without being used: a class A network (16 million hosts) is far too large for any single organisation, while a class C (254 hosts) is too small for many.
Special addresses
- Network address: all HostID bits set to 0; identifies the whole network, appears only in routing tables, never assigned to a host. E.g. (class B) gives .
- Direct broadcast address: all HostID bits set to 1; reaches every node of that network. E.g. .
- : "this host", used as source by a host that has no address yet (DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration →).
- : limited broadcast, reaches the whole local network and is never forwarded by routers.
- : loopback, packets never leave the host.
- Private addresses: NAT and Private AddressesPrivate networks (intranets) use TCP/IP with private address blocks (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) that may be reused by different intranets but are never routed in the public Internet; to reach the Internet an intranet needs an application proxy or NAT, a router that translates private to public addresses using a NAT table and per-session mappings: Basic NAT translates only the IP address one to one, NAPT also translates the port so many sessions share one public IP, and Twice NAT adds DNS support and static mappings so sessions can also start from outside.NAT and Private Addresses →.
Classless addressing (CIDR)
The boundary between NetID and HostID can fall anywhere ( from 0 to 32). Large blocks can be split (subnetting) or small ones merged (supernetting): Subnetting, VLSM and SupernettingSubnetting splits an address block into smaller subnets by lengthening the mask (2^s subnets when s bits are borrowed), supernetting does the opposite by shortening the prefix to merge contiguous blocks; design rules for variable-size subnets are power-of-two sizes M with M at least hosts plus 2, prefix 32 minus log2 M, and start addresses divisible by M (largest subnet first), while 2^j blocks of prefix n aggregate into one block of prefix n minus j only if contiguous and aligned.Subnetting, VLSM and Supernetting →. The longer the prefix, the smaller the network.
Formula (CIDR block ). addresses; network address = first bits unchanged and the rest set to 0; broadcast = first bits unchanged and the rest set to 1; usable hosts .
Example. : (30 hosts). The significant byte is the last, ; keep the first 3 bits () and zero the other 5: . Network , broadcast , i.e. .
The same address belongs to different blocks for different . For : gives network ; gives (up to ); gives (up to ); gives ; gives (up to ); gives (up to ).
Netmask
Definition. The netmask has the first bits set to 1 and the other to 0. For : .
AND with a mask bit of 1 keeps the address bit, with 0 clears it; OR with 1 forces the bit to 1. Hence:
Formula. , network , broadcast . An address belongs to the network with address and mask if and only if .
Mask byte values (ones always contiguous from the left): (8 ones), (7), (6), (5), (4), (3), (2), (1), .
Example. with : last byte ; last byte , so ; OR gives .
Membership. Network , (, addresses, up to ). For : , AND , so : not a member. For : : member.
Block assignment rules
ICANN assigns blocks to ISPs. For CIDR to work: (1) the number of addresses must be a power of 2 (round up); (2) the prefix length is ; (3) the first address must be a multiple of (alignment), since the host bits go from all 0 to all 1.
Examples. 1000 addresses give , , a valid block is ( is a multiple of 4). 3000 hosts give , , valid block .
Typical exercise. : , mask on the last byte ; network , , 6 hosts, broadcast , netmask .
Is it a network address? It depends on : yes; no (the network is ); yes.
Versione ripasso
Network layer
- Host-to-host delivery; the protocol runs in every router. Services: encapsulation (routers do not change addresses), routing (builds tables: Routing Algorithms - Link State and Distance VectorRouting finds least-cost paths in a weighted graph where routers are nodes and networks between routers are edges. Link state floods each router's local links (LSPs) so every router knows the whole graph and runs Dijkstra; distance vector has each router exchange its distance vector with neighbours only and update it with Bellman-Ford, D(A,w)=min(D(A,w), D(A,Y)+d(Y,w)), which converges in at most n-1 rounds but suffers from count to infinity (limited infinity of 16, hold down, triggered updates, split horizon, poison reverse); path vector announces whole paths, chooses by policy and detects loops by finding itself in the path.Routing Algorithms - Link State and Distance Vector →), forwarding (reads destination, picks output interface: Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →).
- Companions of IP: ICMP (ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →), IGMP, ARP (ARP - Address Resolution ProtocolTo place an IP datagram in a frame a node needs the MAC address of the next hop, obtained with ARP: a broadcast request (destination MAC FF:FF:FF:FF:FF:FF, carrying the sender's IP and MAC and the wanted IP) and a unicast reply with the wanted MAC, stored in the ARP cache; ARP always resolves the next hop (destination host or router), never the final destination, and since broadcasts do not leave the subnet a router can answer with its own MAC (proxy ARP).ARP - Address Resolution Protocol →).
- One host, three identifiers: name (DNS), IP, MAC.
IPv4 address
- 32 bits identifying a connection; dotted decimal; addresses. Prefix (NetID, bits) + suffix (HostID, bits).
- Classes: A (0, ), B (10, ), C (110, ), D multicast (1110), E reserved (1111); obsolete because of address exhaustion.
- Network address: HostID all 0 (tables only). Direct broadcast: HostID all 1. this host; limited broadcast; loopback.
CIDR and netmask
; network = rest of bits 0; broadcast = rest of bits 1; hosts . Mask: ones then zeros. Network ; broadcast ; is in network iff .
- : , network , broadcast .
- : network , broadcast , mask , 6 hosts.
- Mask bytes: = 8,7,6,5,4,3,2,1,0 ones.
- Block rules: addresses, , network address multiple of . 1000 addresses give ; 3000 hosts give .
- Typical errors: calling an address "network" just because it ends in 0 without checking ; forgetting the ; confusing host bits with the prefix length.