The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS...

14
Patt-Shamir Lecture 9 2 4 bits 4 bits The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address destination IP Address (OPTIONS) (PAD) <=64 KBytes Offset within original packet Hop count 8 bits 3 bits 13 bits 32 bits Patt-Shamir Lecture 9 3 Types of Service (TOS) An early attempt to support Quality if Service (QoS). Bits 0-2: precedence (0..7, 0 is lowest) Bit 3: Delay . 1=low delay requested. Bit 4: Throughput. Bit 5: Reliability. Bits 6-7: unused. …But most routers ignore the TOS field! More on QoS later in the course. Patt-Shamir Lecture 9 4 Fragmentation A Ethernet MTU=1500 bytes MTU=1500 bytes B Source Destination MTU<1500 bytes Problem: A router may receive a packet larger than the maximum transmission unit (MTU) of the outgoing link. R1 R2 Solution: R1 fragments the IP datagram into multiple, self-contained datagrams. Data HDR (ID=x) Data HDR (ID=x) Data HDR (ID=x) Data HDR (ID=x) Offset>0 More Frag=0 Offset=0 More Frag=1 Patt-Shamir Lecture 9 5 Fragmentation Example ID =x offset =0 fragflag =0 length =4000 ID =x offset =0 fragflag =1 length =1500 ID =x offset =1480 fragflag =1 length =1500 ID =x offset =2960 fragflag =0 length =1040 One large datagram becomes several smaller datagrams

Transcript of The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS...

Page 1: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Patt-ShamirLecture 9 2

4 bits4 bits

The IPv4 Datagram

Flags

vers

TTL

TOS

checksum

HLen(x32b) Datagram Length (bytes)

ID FRAG Offset

Protocol

source IP Address

destination IP Address

(OPTIONS) (PAD)

<=64 KBytes

Offset within original packet

Hop count

8 bits 3 bits 13 bits32 bits

Patt-ShamirLecture 9 3

Types of Service (TOS)

An early attempt to support Quality if Service (QoS).• Bits 0-2: precedence (0..7, 0 is lowest)• Bit 3: Delay . 1=low delay requested.• Bit 4: Throughput. • Bit 5: Reliability.• Bits 6-7: unused.…But most routers ignore the TOS field! More on QoS later in the course.

Patt-ShamirLecture 9 4

Fragmentation

A

Ethernet MTU=1500 bytes MTU=1500 bytes

BSource DestinationMTU<1500 bytes

Problem: A router may receive a packet larger than the maximum transmission unit (MTU) of the outgoing link.

R1 R2Solution: R1 fragments the IP datagram into multiple, self-contained datagrams.

Data HDR (ID=x)

Data HDR (ID=x) Data HDR (ID=x) Data HDR (ID=x)

Offset>0More Frag=0

Offset=0More Frag=1

Patt-ShamirLecture 9 5

Fragmentation Example

ID=x

offset=0

fragflag=0

length=4000

ID=x

offset=0

fragflag=1

length=1500

ID=x

offset=1480

fragflag=1

length=1500

ID=x

offset=2960

fragflag=0

length=1040

One large datagram becomesseveral smaller datagrams

Page 2: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Patt-ShamirLecture 9 6

Fragmentation

• Fragments re-assembled only by the destination host– Set timer when first fragment arrives, discard packet if not

all fragments arrive before timeout.

• Fragmentation can be avoided by MTU discovery that finds the smallest MTU along the path– Path MTU discovery: test for fragmentation by sending

various size datagrams. – But routing may change…

• Most links today: MTU ≥ 1500 bytes.

Patt-ShamirLecture 9 7

Time to Live (TTL)

Idea: Prevent packets from remaining in the network forever.

• One method: use timeouts.– Requires synchronized clocks!

• Internet method: hop count.– Hop = router-router path.– Sender initializes TTL (at most 255)– Every time a packet reaches a router, TTL counter decremented

by 1– When TTL reaches 0, packet dropped and error message sent

back to sender

Patt-ShamirLecture 9 8

Protocols

Tells what type is the data. E.g., • TCP=6• UDP=17• IP=4 (why need IP?)• ICMP=1See www.iana.org/assignments/protocol-numbers

Patt-ShamirLecture 9 9

ICMP: Internet Control Message Protocol

• Formally: a transport layer – ICMP msgs carried in IP datagrams

• But not general: Kind of IP control messages. Used by hosts, routers, gateways to communicate network-level information– error reporting: unreachable host,

network, port, protocol– echo request/reply (used by ping)

• ICMP message: type; code; first 8 bytes of IP datagram causing error

Type Code description0 0 echo reply (ping)3 0 dest. network unreachable3 1 dest host unreachable3 2 dest protocol unreachable3 3 dest port unreachable3 6 dest network unknown3 7 dest host unknown4 0 source quench (congestion

control - not used)8 0 echo request (ping)9 0 route advertisement10 0 router discovery11 0 TTL expired12 0 bad IP header

Page 3: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

IP Addresses

10

Addresses and Interfaces

• Interface (NIC): connection between host or router and the physical network link– hosts may have multiple interfaces (routers always do)

• Interfaces have IP addresses: Hosts (or routers) don’t!

to network

interface

Patt-ShamirLecture 9 11

IP Addressing

• IP address (v4):– 32 bits– high order bits: network– low order bits: host

IP’s definition of network: Set of devices that can communicate directly (in the datalink layer), without any router in the middle

223.1.1.1

223.1.1.2

223.1.1.3

223.1.1.4 223.1.2.9

223.1.2.2

223.1.2.1

223.1.3.2223.1.3.1

223.1.3.27

network consisting of 3 IP networks(for IP addresses starting with 223, first 24 bits are network address)

LAN

Patt-ShamirLecture 9 12

IP Addressing

How to find the networks?• Detach each interface from

router, host• create “islands of isolated

networks”

223.1.1.1

223.1.1.3

223.1.1.4

223.1.2.2223.1.2.1

223.1.2.6

223.1.3.2223.1.3.1

223.1.3.27

223.1.1.2

223.1.7.0

223.1.7.1223.1.8.0223.1.8.1

223.1.9.1

223.1.9.2

Interconnected system consisting

of six networksPatt-Shamir

Lecture 9 13

Page 4: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Structure of IP AddressesOriginally there were 5 classes:

CLASS “A” 1 7

0 Net ID Host-ID

CLASS “B” 10 Net ID Host-ID

24

2 14 16

CLASS “C” 110 Net ID Host-ID3 21 8

CLASS “D” 1110 Multicast Group ID4 28

CLASS “E” 11110 Reserved5 27

128 networks16M hosts

16K networks64K hosts

2M networks256 hosts

256MIDs

Host IDs convention: 0=self, 0xff…=all, 127.* = loopbackPatt-Shamir

Lecture 9 14

IP Addresses: Example

Class “A” address: www.mit.edu 18.7.22.83 (0<18<128 => Class A)

Class “B” address: www.tau.eng.edu 132.66.48.13 (128 ≤ 132 < 192) => Class B)

Some IP lingo:•Dotted Decimal Notation•Octets

Patt-ShamirLecture 9 15

Problem: Address classes too “rigid”

Usually, Class C too small and Class B too big Even small organizations have > 255 hosts. But there

are only 16K Class B network IDs. Wastage and shortage of addresses!

Organizations with internal routers need to have a separate network ID for each link.

Every router must know about every network ID in every organization large address tables.

Patt-ShamirLecture 9 16

IP Addressing

Hence, two solutions:Subnetting: subdivide a network ID

hierarchically (used within an organization). A hack on top of the class systemClassless Interdomain Routing (CIDR,

“supernetting”): Forget classes. Network ID can be any prefix of the IP address.

Patt-ShamirLecture 9 17

Page 5: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Subnetting

CLASS “B”e.g. Company 10 Net ID Host-ID

2 14 16

10 Net ID Host-ID2 14 16

0000Subnet ID (20) Subnet

Host ID (12)

10 Net ID Host-ID2 14 16

1111Subnet ID (20) Subnet

Host ID (12)

10 Net ID Host-ID2 14 16

000000

Subnet ID (22) SubnetHost ID (10)

10 Net ID Host-ID2 14 16

1111011011

Subnet ID (26) SubnetHost ID (6)

e.g. Site

e.g. Dept

Patt-ShamirLecture 9 18

Subnetting

• Subnetting is a form of hierarchical routing.• Representation: an address + a bitmask.

– Mask 0xffff0000 (or 255.255.0.0): the first 16 bits are the subnet ID, and the last 16 bits are the host ID.

• Advantage: allows for the flexible partition of large networks (typically, type B).

• Shortcoming: – must be configured in each host with its IP address– subnet is still part of its parent network: switching ISP IP

addresses will change.

Patt-ShamirLecture 9 19

CIDR AddressingClassless InterDomain Routing

IP address space broken into intervals of length 2k for an integer k≥0, aligned.

Representation: the common prefix. Denoted x/y, meaning yfirst bits of x.

Example: 128.9/16 represents the addresses in the interval [128.9.0.0 … 128.9.255.255].

0 232-1

128.9/16

128.9.0.0

216

142.12/1965/8

128.9.16.14 Patt-ShamirLecture 9 20

0 232-1

128.9/16

128.9.16.14

128.9.16/20 128.9.176/20

128.9.19/24128.9.25/24

Intervals may overlap!Rule: prefer the “longest matching prefix”

CIDR Addressing

Patt-ShamirLecture 9 21

Page 6: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Prefix aggregation: If a service provider serves two organizations with prefixes, it can aggregate them to form a larger prefix (when?).

Reduces size of routing tables. E.g. ISP serves 128.9.14.0/24 and 128.9.15.0/24, it can

tell other routers to send it all packets belonging to the prefix 128.9.14.0/23.

ISP Choice: In principle, an organization can keep its prefix if it

changes service providers.

CIDR Addressing

Patt-ShamirLecture 9 22

IPv6 addresses

• Motivation: too few 32-bit addresses, more functionality required.

• new addresses: 128 bits (!)– X:X:X:X:X:X:X:X where X is 4 hexadecimals– structured hierarchy: 13, 24, 16, 64 bits (last is interface ID). 3

bits identify type, 8 reserved– new “anycast” address: route to “best” of several replicated

servers– Can embed IPv4 addresses

• Penetration is slow... but used in China!

Patt-ShamirLecture 9 23

Forwarding in Routers

Patt-ShamirLecture 8 24

Inside a Router

ForwardingDecision

ForwardingDecision

ForwardingDecision

ForwardingTable

ForwardingTable

ForwardingTable

Interconnect

OutputScheduling

1.2.

3.

Patt-ShamirLecture 8 25

Page 7: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Forwarding in an IP Router

• Lookup packet DA in forwarding table.– If known, forward to correct port.– If unknown (in particular: no default router), drop packet.

• Decrement TTL, update header Checksum.• Forward packet to outgoing interface.• Transmit packet onto link.

Question: How is the address looked up in a real router?

Patt-ShamirLecture 8 26

Routing Tables at a router

128.9/16128.9.16/20

128.9.176/20

128.9.19/24128.9.25/24

142.12/19

65/8

Prefix Port3227213

128.17.14.1128.17.14.1

128.17.20.1

128.17.10.1128.17.14.1

128.17.16.1

128.17.16.1

Next-hop

R1

R2

R3

R4

12

3

128.17.20.1

128.17.16.1

e.g. 128.9.16.14 => Port 2

Forwarding/routing table

Routing table must know next hop for every network on the Internet! Patt-Shamir

Lecture 8 27

Core Router Table Size

source: http://bgp.potaroo.net/

Patt-ShamirLecture 8 28

Required Lookup Performance

Line Line Rate Pktsize=40B Pktsize=240B

T1 1.5Mbps 4.68 Kpps 0.78 Kpps

OC3 155Mbps 480 Kpps 80 Kpps

OC12 622Mbps 1.94 Mpps 323 Kpps

OC48 2.5Gbps 7.81 Mpps 1.3 Mpps

OC192 10 Gbps 31.25 Mpps 5.21 Mpps

Patt-ShamirLecture 8 29

Page 8: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Routing table Structure

Patt-ShamirLecture 8 30

Finding next hop inClass-based addressing

Class A Class B Class C D

212.17.9.4

Class A

Class B

Class C212.17.9.0 Port 4

ExactMatch

Routing Table:

IP Address Space

212.17.9.0

Exact Match: There are many well-known ways to find an exact match in a table.

Patt-ShamirLecture 8 31

Direct Lookup

IP AddressMemory

Next-hop, Port

Problem: With 232 addresses, the memory would require 4 billion entries.

Patt-ShamirLecture 8 32

Associative Lookups“Contents addressable memory” (CAM)

NetworkAddress

PortNumber

AssociativeMemory or CAM

Search Data

32

PortNumber

Hit?

Advantages:• Simple

Disadvantages• High Power• Small• Expensive

Patt-ShamirLecture 8 33

Page 9: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Hashed Lookups

HashFunction

Memory

Add

ress

Dat

a

Search Data

log2N

AssociatedData

Hit?

Address{1632

Patt-ShamirLecture 8 34

Lookups Using HashingAn example

Hashing Function 16

#1 #2 #3 #4

#1 #2

#1 #2 #3Linked list of entrieswith same hash key.

Memory

Search Data

AssociatedData

Hit?32

Patt-ShamirLecture 8 35

Lookups Using Hashing

Advantages:• Simple

• Expected lookup time can be small

Disadvantage• Non-deterministic lookup time

Patt-ShamirLecture 8 36

Classless Addressing: CIDR

0 232-1

128.9/16

128.9.16.14

128.9.16/20 128.9.176/20

128.9.19/24128.9.25/24

Most specific route = “longest matching prefix”

Problem: How can we look up addresses if they are not an exact match?

Patt-ShamirLecture 8 37

Page 10: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Ternary CAMs: CAMs with *’s

10.1.1.32 1

10.1.1.0 2

10.1.3.0 3

10.1.0.0 4

255.255.255.255255.255.255.0

255.255.255.0

255.255.0.0

255.0.0.010.0.0.0 4

Value Mask

Priority Encoder

Port

Associative Memory

Port

Note: Most specific routes appear closest to top of table

Patt-ShamirLecture 8 38

Trees and Tries

Binary Search Tree:

< >

< > < >

log2 N

N entries

Binary Search Trie: (“reTRIEval”)

0 1

0 1 0 1

111010

Requires 32 memory references, regardless of number of addresses.

Patt-ShamirLecture 8 39

Search TriesMultiway tries reduce the number of memory references

16-ary Search Trie

0000, ptr 1111, ptr

0000, 0 1111, ptr

000011110000

0000, 0 1111, ptr

111111111111

• Each node has 16 children, but only children that lead to an existing leaf are non-NULL.• Why not keep increasing the degree of the trie?

Patt-ShamirLecture 8 40

Longest prefix matches using Binary Tries

Example Prefixes:a) 00001b) 00010c) 00011d) 001e) 0101f) 011g) 100h) 1010i) 1100j) 11110000

e

f g

h i

j

0 1

a b c

d

Patt-ShamirLecture 8 41

Page 11: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Patricia Tries

Example Prefixes:a) 00001b) 00010c) 00011d) 001e) 0101f) 011g) 100h) 1010i) 1100j) 11110000

e

f g

h i

Skip 5j

0 1

a b c

d

Patt-ShamirLecture 8 42

IP helpers

Patt-ShamirLecture 9 44

DHCPDynamic Host Configuration Protocol

Goal: dynamically obtain an IP address from network server – Can renew its lease on address in use– Allows reuse of addresses– Support for mobile users

DHCP overview:– host broadcasts “DHCP discover” msg– DHCP server responds with “DHCP offer” msg– host requests IP address: “DHCP request” msg– DHCP server sends address: “DHCP ack” msg

Patt-ShamirLecture 9 45

NATNetwork Address Translation

Datagrams with source or destination in this networkhave 10.0.0/24 address for source, destination (as usual)

10.0.0.1

10.0.0.2

10.0.0.3

10.0.0.4

138.76.29.7

local network(e.g., home network)

10.0.0/24

rest ofInternet

All datagrams leaving local network have same single source NAT IP address: 138.76.29.7 and different source port numbers

10.0.0.0/8172.16.0.0/12

192.168.0.0/16NAT reserved

Page 12: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Patt-ShamirLecture 9 46

NAT idea

• Use one of three reserved blocks for all internal IP addresses– (10/8, 172.16/12, 192.168/16)

• Within internal network—all as before• Connections going outside are translated by

the NAT server that keeps the translation table – Use transport level IDs (port numbers).

Patt-ShamirLecture 9 47

NAT properties

• Allow a complete IP network to have one external IP address

• Can change internal addresses without notifying outside world

• Can change external address (e.g., ISP) without notifying internal devices

• devices inside local net not directly visible or reachable by outside world (good security, bad flexibility).

Patt-ShamirLecture 9 48

DNS & ARP

Patt-ShamirLecture 9 49

• Domain names: application level

• IP addresses: network level

• MAC: Data link (LAN) level

3 Addressing Schemes

www.tau.ac.il

132.66.16.6

E6-E9-00-17-BB-4B

Page 13: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

Patt-ShamirLecture 9 50

Address Translation

Hostname (bakara.eng.tau.ac.il)

IP address (132.66.48.12)

MAC address (80:20:9A:3A:99)

DNS

ARP

Patt-ShamirLecture 9 51

DNS: Domain Name System

• Distributed database: a hierarchy of many name servers.– Supports both queries (domain name ↔ IP address), and

updates. Hierarchical authority, hierarchical queries

• Application-layer protocol: host, routers, name servers communicate to resolve names – core Internet function implemented as application-layer

protocol!– This is a function for users (not only humans, though)

Note: routers don’t maintain any DNS-related info

Patt-ShamirLecture 9 52

DNS: Root name servers

• contacted by local name server when can’t resolve name

• root name server:– contacts authoritative

name server if name mapping not known

– gets mapping– returns mapping to

local name server• 13 root entities, ~300

servers

source: root-servers.org

Patt-ShamirLecture 9 53

Simplified DNS example

host surf.eurecom.fr wants IP address of gaia.cs.umass.edu

1. Contacts its local DNS server, dns.eurecom.fr

2. dns.eurecom.fr contacts root name server, if necessary

3. root name server contacts authoritative name server, dns.umass.edu, if necessary

requesting hostsurf.eurecom.fr

gaia.cs.umass.edu

root name server

authorititive name serverdns.umass.edu

local name serverdns.eurecom.fr

1

23

45

6

Page 14: The IPv4 Datagram Types of Service (TOS) · 2013-05-11 · The IPv4 Datagram Flags vers TTL TOS checksum HLen (x32b) Datagram Length (bytes) ID FRAG Offset Protocol source IP Address

DNS: iterated queriesrecursive query:• puts burden of name

resolution on contacted name server

• heavy load?

iterated query:• contacted server replies

with name of server to contact

• “I don’t know this name, but ask this server”

requesting hostsurf.eurecom.fr

gaia.cs.umass.edu

root name server

local name serverdns.eurecom.fr

1

24

5 6

authoritative name serverdns.cs.umass.edu

intermediate name serverdns.umass.edu

7

8

iterated query3

Patt-ShamirLecture 9 55

ARPAddress Resolution Protocol

• MAC address ↔ IP address• Each IP node (Host, Router) on the LAN has ARP module and

Table• ARP Table: IP/MAC address mappings for some LAN nodes

< IP address; MAC address; TTL>< ………………………….. >

• TTL (Time To Live):timer, typically

10’s of minutes

Patt-ShamirLecture 9 56

ARP (more)

Host A wants to send packet to destination IP addr XYZ on same LAN

• By subnet mask, knows that on same LAN go to local ARP• ARP looks in its cache for IP addr XYZ; if found done.• Otherwise, ARP module broadcasts ARP pkt “who is XYZ?”• ALL nodes on the LAN accept and inspect the ARP pkt• Node XYZ responds with unicast ARP pkt to A: < XYZ, MAC

(XYZ) >• All nodes store MAC address in their local ARP cache• Entries expire after a few minutes

Patt-ShamirLecture 9 57

IP Forwarding Decision

1. Given a packet: determine the network prefix of the destination in the packet (CIDR!)

2. Is the destination is on the same network? Decide by own IP address, destination IP address and subnet

mask3. If yes, immediate destination = final destination4. Else, use routing table to find immediate destination ( which is

a router)5. Use ARP to find datalink (MAC) address6. Send packet over to datalink immediate destination