Salta al contenuto
Note per Studenti Network Layer and IPv4 Addressing Report

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:

  1. 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.
  2. 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 →).
  3. 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. 10000011 10101111 00010101 0000000110000011\ 10101111\ 00010101\ 00000001 is 131.175.21.1131.175.21.1, because 100000112=128+2+1=13110000011_2=128+2+1=131, 101011112=128+32+8+4+2+1=17510101111_2=128+32+8+4+2+1=175, 000101012=16+4+1=2100010101_2=16+4+1=21, 000000012=100000001_2=1.

There are 232=4 294 967 2962^{32}=4\,294\,967\,296 addresses. In general hh bits give 2h2^h values and NN values need h=log⁡2Nh=\log_2N bits: this relation is used throughout subnetting.

Prefix and suffix

The first nn bits are the prefix (NetID), identifying the network; the other 32−n32-n bits are the suffix (HostID), identifying the host inside it. Nodes in the same network share the NetID. Example with n=16n=16: in 131.175.12.8131.175.12.8 the NetID is 131.175131.175 and the HostID is 12.812.8.

Classful addressing (obsolete)

In the early Internet the prefix had a fixed length chosen among n=8,16,24n=8,16,24, recognisable from the first bits:

class first bits first byte nn networks hosts per network
A 0 0 - 127 8 27=1282^7=128 (126 usable) 224−2=16 777 2142^{24}-2=16\,777\,214
B 10 128 - 191 16 214=16 3842^{14}=16\,384 216−2=65 5342^{16}-2=65\,534
C 110 192 - 223 24 221=2 097 1522^{21}=2\,097\,152 28−2=2542^8-2=254
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

Classless addressing (CIDR)

The boundary between NetID and HostID can fall anywhere (nn 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 a.b.c.d/na.b.c.d/n). N=232−nN=2^{32-n} addresses; network address = first nn bits unchanged and the rest set to 0; broadcast = first nn bits unchanged and the rest set to 1; usable hosts N−2N-2.

Example. 167.199.170.82/27167.199.170.82/27: N=25=32N=2^5=32 (30 hosts). The significant byte is the last, 82=01010010282=01010010_2; keep the first 3 bits (010010) and zero the other 5: 010000002=6401000000_2=64. Network 167.199.170.64/27167.199.170.64/27, broadcast 010111112=9501011111_2=95, i.e. 167.199.170.95167.199.170.95.

The same address belongs to different blocks for different nn. For 230.8.24.56/n230.8.24.56/n: n=16n=16 gives network 230.8.0.0230.8.0.0; n=20n=20 gives 230.8.16.0230.8.16.0 (up to .31.255.31.255); n=26n=26 gives 230.8.24.0230.8.24.0 (up to .63.63); n=27n=27 gives 230.8.24.32230.8.24.32; n=29n=29 gives 230.8.24.56230.8.24.56 (up to .63.63); n=31n=31 gives 230.8.24.56230.8.24.56 (up to .57.57).

Netmask

Definition. The netmask has the first nn bits set to 1 and the other 32−n32-n to 0. For n=27n=27: 255.255.255.224255.255.255.224.

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. N=NOT(M)+1N=\text{NOT}(M)+1, network =IP AND M=\text{IP}\ \text{AND}\ M, broadcast =IP OR NOT(M)=\text{IP}\ \text{OR}\ \text{NOT}(M). An address XX belongs to the network with address RR and mask MM if and only if X AND M=RX\ \text{AND}\ M=R.

Mask byte values (ones always contiguous from the left): 255255 (8 ones), 254254 (7), 252252 (6), 248248 (5), 240240 (4), 224224 (3), 192192 (2), 128128 (1), 00.

Example. 167.199.170.82167.199.170.82 with M=255.255.255.224M=255.255.255.224: last byte 01010010 AND 11100000=01000000=6401010010\ \text{AND}\ 11100000=01000000=64; NOT(M)\text{NOT}(M) last byte =00011111=31=00011111=31, so N=32N=32; OR gives 01011111=9501011111=95.

Membership. Network 205.16.32.0205.16.32.0, M=255.255.248.0M=255.255.248.0 (/21/21, 211=20482^{11}=2048 addresses, up to 205.16.39.255205.16.39.255). For 205.16.42.56205.16.42.56: 42=0010101042=00101010, AND 11111000=00101000=4011111000=00101000=40, so 205.16.40.0≠205.16.32.0205.16.40.0\neq205.16.32.0: not a member. For 205.16.37.44205.16.37.44: 37=00100101→00100000=3237=00100101\to00100000=32: member.

Block assignment rules

ICANN assigns blocks to ISPs. For CIDR to work: (1) the number of addresses MM must be a power of 2 (round up); (2) the prefix length is n=32−log⁡2Mn=32-\log_2M; (3) the first address must be a multiple of MM (alignment), since the log⁡2M\log_2M host bits go from all 0 to all 1.

Examples. 1000 addresses give 1024=2101024=2^{10}, n=22n=22, a valid block is 18.14.12.0/2218.14.12.0/22 (1212 is a multiple of 4). 3000 hosts give 4096=2124096=2^{12}, n=20n=20, valid block 18.14.0.0/2018.14.0.0/20.

Typical exercise. 190.87.140.202/29190.87.140.202/29: 202=11001010202=11001010, mask on the last byte 11001000=20011001000=200; network 190.87.140.200190.87.140.200, N=8N=8, 6 hosts, broadcast 200+7=207200+7=207, netmask 255.255.255.248255.255.255.248.

Is it a network address? It depends on nn: 192.168.10.0/24192.168.10.0/24 yes; 192.168.10.0/16192.168.10.0/16 no (the network is 192.168.0.0/16192.168.0.0/16); 192.168.10.128/28192.168.10.128/28 yes.

Versione ripasso

Network layer

IPv4 address

  • 32 bits identifying a connection; dotted decimal; 2322^{32} addresses. Prefix (NetID, nn bits) + suffix (HostID, 32−n32-n bits).
  • Classes: A (0, n=8n=8), B (10, n=16n=16), C (110, n=24n=24), D multicast (1110), E reserved (1111); obsolete because of address exhaustion.
  • Network address: HostID all 0 (tables only). Direct broadcast: HostID all 1. 0.0.0.00.0.0.0 this host; 255.255.255.255255.255.255.255 limited broadcast; 127.0.0.0127.0.0.0 loopback.

CIDR and netmask

N=232−nN=2^{32-n}; network = rest of bits 0; broadcast = rest of bits 1; hosts N−2N-2. Mask: nn ones then zeros. Network =IP AND M=\text{IP AND }M; broadcast =IP OR NOT(M)=\text{IP OR NOT}(M); XX is in network RR iff X AND M=RX\ \text{AND}\ M=R.

  • 167.199.170.82/27167.199.170.82/27: N=32N=32, network .64.64, broadcast .95.95.
  • 190.87.140.202/29190.87.140.202/29: network .200.200, broadcast .207.207, mask 255.255.255.248255.255.255.248, 6 hosts.
  • Mask bytes: 255,254,252,248,240,224,192,128,0255,254,252,248,240,224,192,128,0 = 8,7,6,5,4,3,2,1,0 ones.
  • Block rules: M=2kM=2^k addresses, n=32−log⁡2Mn=32-\log_2M, network address multiple of MM. 1000 addresses give /22/22; 3000 hosts give /20/20.
  • Typical errors: calling an address "network" just because it ends in 0 without checking nn; forgetting the −2-2; confusing host bits with the prefix length.

Teoria collegata