10/29/2015internet protocol1 ipv4: internet protocol ip is the workhorse protocol of the tcp/ip...
TRANSCRIPT
04/20/23 Internet Protocol 1
IPv4: Internet Protocol
• IP is the workhorse protocol of the TCP/IP protocol suite
• IP provides an unreliable, connectionless, datagram delivery service
• The internet protocol implements two basic functions: addressing and fragmentation.
• RFC791 is the official specification of IP
04/20/23 Internet Protocol 2
The Workhorse
ARP RARPHardwareInterface
ICMP IGMPIP
TCP UDP
UserProcess
UserProcess
UserProcess
UserProcess
application
transport
network
link
04/20/23 Internet Protocol 3
IP Header
Version Hdr Len Type of Service Total Length (in bytes)
Identification Flags Fragment offset
168
Time to Live Protocol Checksum
Source IP Address
Destination IP Address
31
20 bytes
options (if any)
data
04/20/23 Internet Protocol 4
Network Byte Ordering
• Multi-byte numbers can be stored in one of two ways:– 6000010 = 00000000 00000000 11101010 01100000
• Network byte order is big endian
Address Big Endian Little EndianAddr0 00000000 01100000Addr1 00000000 11101010Addr2 11101010 00000000Addr3 01100000 00000000
04/20/23 Internet Protocol 5
IP Header Fields
Field DescriptionVersion The Version field indicates the format of the internet
header. The current protocol version is 4 (sometimescalled IPv4)
Header Length The length of the header in 32-bit words. Note thatthe minimum value for a correct header is 5.
Total Length The total length of the IP datagram in bytes (data andheader)
Time to Live Sets an upper limit on the number of routers throughwhich a datagram can pass. It is initialized by thesender (often 32 or 64) and decremented by one eachtime the packet passes through a router. When itreaches 0, the packet is discarded
04/20/23 Internet Protocol 6
Type of Service
• The IP protocol provides a (rather limited) facility for upper layer protocols to convey hints to the Internet Layer about how the tradeoffs should be made for the particular packet
3-bitprecedence
4-bitTOS
MBZ
04/20/23 Internet Protocol 7
TOS Field Values
• There are 4 defined values for the TOS field
• Note these values are defined as integers, not as bits
Value Meaning1000 Minimize delay0100 Maximize throughput0010 Maximize reliability0001 Minimize monetary cost0000 Normal service (default)
04/20/23 Internet Protocol 8
Recommended TOS ValuesApplication Minimize
DelayMaximizeThroughput
MaximizeReliability
MinimizeMonetaryCost
Hex Value
Telnet/Rlogin 1 0 0 0 0x10FTP Control Bulk
10
01
00
00
0x100x08
TFTP 1 0 0 0 0x10SMTP Command Data
10
01
00
00
0x100x08
DNS UDP query TCP query Transfer
100
001
000
000
0x100x000x08
ICMP Error Query
00
00
00
00
0x000x00
SMNP 0 0 1 0 0x02BOOTP 0 0 0 0 0x00NNTP 0 0 0 1 0x01
04/20/23 Internet Protocol 9
Fragmentation
• The physical layer often imposes an upper limit on the size of the frame that can be transmitted
• IP compares the MTU (maximum transmission unit) with the datagram size and performs fragmentation, if necessary
• Fragmentation can take place at the original host or at an intermediate router
• IP datagrams are not reassembled until they reach their final destination
04/20/23 Internet Protocol 10
Fragmentation and the Header
• The following fields are used in fragmentation– identification
• contains a unique value for each IP datagram that the sender transmits
– flags
– fragment offset• the offset of the fragment from the beginning of the original
datagram
MBZchecking bit
Don’tfragment
Morefragments
04/20/23 Internet Protocol 11
Fragmentation
• If fragmentation must occur…– if the “don’t fragment” bit is turned on the packet is
discarded
– the packet is split into fragments• the header is basically copied except for…
– total length is changed to the size of the fragment
– the fragmentation offset is set to the the offset of the fragment from the beginning of the original datagram
– the “more fragments” bit is turned on in every fragment except for the last one
04/20/23 Internet Protocol 12
Reassembly
• The identification field is used to ensure that fragments of different datagrams are not mixed.
• The fragment offset field tells the receiver the position of a fragment in the original datagram
• The fragment offset and length determine the portion of the original datagram covered by this fragment
• The more-fragments flag indicates (by being reset) the last fragment
04/20/23 Internet Protocol 13
Protocol Field
• This field indicates the next level protocol used in the data portion of the internet datagram
• The values for various protocols are specified in RFC1060 (Assigned Numbers)
Number Protocol0 Reserved1 ICMP2 IGMP6 TCP17 UDP
Decimal Keyword Protocol References
0 Reserved [JBP]
1 ICMP Internet Control Message [97,JBP]
2 IGMP Internet Group Management [43,JBP]
3 GGP Gateway-to-Gateway [60,MB]
4 Unassigned [JBP]
5 ST Stream [49,JWF]
6 TCP Transmission Control [106,JBP]
7 UCL UCL [PK]
8 EGP Exterior Gateway Protocol [123,DLM1]
9 IGP any private interior gateway [JBP]
10 BBN-RCC-MON BBN RCC Monitoring [SGC]
11 NVP-II Network Voice Protocol [22,SC3]
12 PUP PUP [8,XEROX]
13 ARGUS ARGUS [RWS4]
14 EMCON EMCON [BN7]
15 XNET Cross Net Debugger [56,JFH2]
16 CHAOS Chaos [NC3]
17 UDP User Datagram [104,JBP]
18 MUX Multiplexing [23,JBP]
19 DCN-MEAS DCN Measurement Subsystems [DLM1]
20 HMP Host Monitoring [59,RH6]
21 PRM Packet Radio Measurement [ZSU]
22 XNS-IDP XEROX NS IDP [133,XEROX]
04/20/23 Internet Protocol 14
04/20/23 Internet Protocol 15
Header Checksum
• The header checksum is calculated over the IP header only
• The checksum is calculated as follows:– set the checksum field to 0
– Add all the 16 bit values in the header together, minus the checksum
– Take the one’s complement of the calculated value
– the 16-bit one’s complement of this sum is stored in the checksum field
04/20/23 Internet Protocol 16
Header Checksum
• When an IP datagram is received, the 16-bit one’s complement sum of the header is calculated
• Since the receiver’s calculated checksum contains the checksum stored by the sender, the calculated result should be all ones
• If the checksum is wrong, the packet is quietly discarded. No error messages are generated
• ICMP, IGMP, UDP, and TCP all use the same checksum
04/20/23 Internet Protocol 17
Addressing
• A distinction is made between names, addresses, and routes– A name indicates what we seek
– An address indicates where it is
– A route indicates how to get there
• The internet protocol deals primarily with addresses. It is the task of higher level protocols to make the mapping from names to addresses.
04/20/23 Internet Protocol 18
IP Addresses
• Every interface on the internet must have a unique Internet Address (also called an IP address)
• IP addresses are 32-bits numbers• The addresses are not flat, they are divided into
two components: the host address and the network address
• The number of bits assigned to the host portion and network portion of the address varies depending on the class of the address
04/20/23 Internet Protocol 19
IP Address Classes
netid
netid
netid
hostid
hostid
hostid
multicast group ID
(reserved for future use)
0
0
0
0
0
1
11
1 1 1
1 1 1 1
Class A
Class B
Class C
Class D
Class E
7 bits
8 bits
24 bits
14 bits 16 bits
21 bits
28 bits
27 bits
04/20/23 Internet Protocol 20
Dotted Decimal Notation
• IP addresses are normally written as four decimal numbers, one for each byte of the address.– 129.21.38.169
• The easiest way to differentiate between the classes is to look at the first number
Class RangeA 0.0.0.0 to 127.255.255.255B 128.0.0.0 to 191.255.255.255C 192.0.0.0 to 223.255.255.255D 224.0.0.0 to 239.255.255.255E 240.0.0.0 to 247.255.255.255
04/20/23 Internet Protocol 21
Assigning IP Addresses
• Since every interface must have a unique IP address, there must be a central authority for assigning numbers
• That authority is the Internet Network Information Center, called the InterNIC.
• The InterNIC assigns only network ids, the assignment of host ids is up to the system administrator
04/20/23 Internet Protocol 22
Subnet Addressing
• The original view of the Internet universe was a two-level hierarchy:– the top level the Internet as a whole– the level below it individual networks, each
with its own network number.• In this two-level model, each host sees its network
as a single entity
04/20/23 Internet Protocol 23
Subnet Addressing
• While the two-level view has proved simple and powerful, a number of organizations have found it inadequate, and have added a third level to the interpretation of Internet addresses.
• In this view, a given Internet network is divided into a collection of subnets.
• The three-level model is useful in networks belonging to moderately large organizations
04/20/23 Internet Protocol 24
Subnet Addressing
• Locally IP addresses consist of three parts:– network ID
– subnet ID
– host ID
• Outside of the subnetted network the addresses are handled normally
• Inside the subnet, the network portion of the address is extended for local routing purpose
04/20/23 Internet Protocol 25
Subnet Masks
• Once the decision to subnet has been made, the local administrator must decide how many bits to allocate to the subnet ID
• A common division is to use the 8-bit boundary in the 16 bits of a host ID in a class B address
• A subnet mask is used to divide the local address into network and host portions
• Subnetting effectively hides the details of the internal network to external routers
04/20/23 Internet Protocol 26
Special IP Addresses
IP Address Can Appear asNet ID Subnet ID Host ID Source? Destination?
Description
00
0hostid
OKOK
NeverNever
This host on this netSpecified host on this net
127 anything OK OK Loopback address255netidnetidnetid
Subnetid255
255255255255
NeverNeverNeverNever
OKOKOKOK
Limited broadcast (never forwarded)Net-directed broadcast to netidSubnet-direct broadcast to netid, subnetidAll-subnets-directed broadcast to netid
04/20/23 Internet Protocol 27
IP Options Field
• The options field is a variable-length list of optional information for the datagram
• The options currently defined are– security and handling restrictions (RFC1108)
– record route
– timestamp
– loose & strict source routing
• The options field always ends on a 32-bit boundary
04/20/23 Internet Protocol 28
IP Routing
• Routing is one of the most important functions of IP
• Datagrams to be routed can either be generated on the local host or on some other host
• If a machine is not configured as a router, datagrams received through network interfaces that are not addressed to the machine are dropped
04/20/23 Internet Protocol 29
Host Routing
• Conceptually IP routing is easy, especially for a host– Remember the structure of an internet address
• If the destination is directly connected to the host, or on a shared network, then the datagram is sent directly
• Otherwise the host sends the datagram to a default router, and lets the router do all of the work
04/20/23 Internet Protocol 30
IP routing Algorithm
• The basic internet routing algorithm is used by both hosts and routers
• The primary difference is that hosts never forward datagrams (except to a default router), whereas routers forward datagrams
• The algorithm uses a routing table to make routing decisions
04/20/23 Internet Protocol 31
A Typical Routing Table
• Each entry in the routing table contains the following information– Destination IP address.
• this can be either a host address or a network address
– IP address of the next-hop router, or the IP address of a directly connected network
– Flags that tell more about the entry
– Which interface the datagram should be passed to for delivery
04/20/23 Internet Protocol 32
IP routing
• IP routing performs the following actions– search the routing table for an entry that matches the
complete destination address. If found, send the packet as indicated
– search the routing table for a matching destination network ID. If found, send the packet as indicated
– search the routing table for a default entry. If found send the packet as indicated
• If none of the steps work, the datagram is undeliverable
04/20/23 Internet Protocol 34
IP Routing
• The routing done by IP, when it searches the routing table and decides which interface to send a packet out, is a routing mechanism
• A routing policy is a set of rules that determines which routes go into the routing table.
• IP performs the routing mechanism while a routing daemon normally provides the routing policy.
04/20/23 Internet Protocol 35
Initializing a Routing Table
• One common way is to execute the route command explicitly from the initialization files when the system is being bootstrapped.
• Some systems allow a default router to be specified in a file such, and this default is added to the routing table on every reboot.
• Other ways to initialize a routing table are to run a routing daemon or to use the newer router discovery protocol.
04/20/23 Internet Protocol 36
Routing Errors
• What happens if there is no default route, and a match is not found for a given destination?
• If the datagram was generated locally, an error is returned to the application that sent the datagram (either “host unreachable” or “network unreachable”)
• What do I do if I am a router?– Sender should be notified of the error