1 Internet Protocol/ Network Layer. 2 Position of IP in TCP/IP protocol suite.
Chapter 8 Internet Protocol (IP) - 國立中興大學 8.pdf · Internet Protocol (IP) Outline o...
Transcript of Chapter 8 Internet Protocol (IP) - 國立中興大學 8.pdf · Internet Protocol (IP) Outline o...
Chapter 8
Internet Protocol (IP)
Outlineo Datagramo Fragmentationo Optionso Checksumo IP package
Figure 8-1
Position of IP in TCP/IP Protocol Suite
The McGraw-Hill Companies, Inc., 2000
IP: Internet Protocolo An unreliable and connectionless datagram
protocol
o A best-effort delivery service
DATAGRAM
8.18.1
The McGraw-Hill Companies, Inc., 2000
Datagramo Datagramsn Packets in the IP layers are called in datagramsn A variable-length packetn Consist of two parts
o Header o Data
Figure 8-2
IP Datagram
The McGraw-Hill Companies, Inc., 2000
IP Datagramo Version (VER)o Header length (HLEN)n Total length of the datagram header in 4-byte
wordsn The length of the header is variable
o 20-60 bytesn If no options, header length is 20 bytes
o HLEN = 5
IP Datagram (Cont.)o Differentiated Services (DS)n IETF has recently changed the interpretation and
name of this fieldn Formerly Service Typen See the following slides
Figure 8-3
Service Type or Differentiated Services
The McGraw-Hill Companies, Inc., 2000
Services Typeo Precedencen 3-bit subfield defines the priority of the datagram
in issues such as congestionn However, this subfield is not used in version 4
o TOS (Type of Service) bitsn 4-bit subfield with each bit having a special
meaningn However, one and only one of the bits can be set
The precedence subfield is The precedence subfield is not used in version 4.not used in version 4.
The McGraw-Hill Companies, Inc., 2000
Types of Services
Minimize delay1000
Maximize throughput0100
Maximize reliability0010
Minimize cost0001
Normal (default)0000
DescriptionTOS Bits
Default Types of Service
Maximize throughput0100DNS (zone)
Normal0000DNS (TCP query)
Minimize delay1000DNS (UDP query)
Maximize throughput0100SMTP (data)
Minimize delay1000SMTP (command)
Minimize delay1000TFTP
Minimize delay1000FTP (control)
Maximize throughput0100FTP (data)
Minimize delay1000TELNET
Maximize reliability0010SNMP
Maximize reliability0010IGP
Minimize cost0001NNTP
Normal0000BOOTP
Normal0000ICMP
DescriptionTOS BitsProtocol
Default Types of Service (Cont.)o Minimum delay
n Interactive activitiesn Activities requiring immediate attentionn Activities requiring immediate response
o Maximum throughputn Send bulk data
o Maximum reliabilityn Management activities
o Minimum monetary costn Background activities, like Usenet News (NNTP)
Differentiated Serviceso The first 6 bits make up the codepointo The last two bits are not usedo The 3 right-most bits are 0sn The 3 left-most bits are interpreted the same as
the precedence bits in the Service Typeo The 3 right-most bits are not all 0sn The 6 bits define 64 services based on the priority
assignment by the Internet or local authorities
Values for Codepoints
Temporary or experimentalXXXX013
LocalXXXX112
Internet (IEFT)XXXXX01
Assigning AuthorityCodepointCategory
IP Datagram (Cont.)o Total length
n The total length (header plus data) of the IP datagram in bytes
n Length of data = total length – header lengtho Identification
n Used in fragmentationo Flags
n Used in fragmentationo Fragmentation offset
n Used in fragmentation
The total length field defines theThe total length field defines thetotal length of the total length of the
datagram including the header.datagram including the header.
The McGraw-Hill Companies, Inc., 2000
Figure 8-4
The McGraw-Hill Companies, Inc., 2000
o Why we need the total length fieldn Layer 2 just drop the header and trailern The remaining is the datagram (length)
o However, in some cases, padding is occurredn Ethernet’s minimum frame data length is 46 bytesn If size of the IP datagram is less than 46, some padding
will be addedn Thus, check the total length field to determine how much
is really data
Encapsulation of a Small Datagram in an Ethernet Frame
Encapsulation of a Small Datagram in an Ethernet Frame (Cont.)
IP Datagram (Cont.)o Time to live
n The maximum number of hops visited by the datagramo Routing table can become corruptedo Intentionally limit the journey of the packet
n Usually two times the maximum number of routers between any two hosts
o Protocoln Define the higher-level protocol that uses the services of
the IP layern Help in the demulplexing proccess
Protocols
OSPF89
UDP17
TCP6
IGMP2
ICMP1
ProtocolValue
Figure 8-5
DeMultiplexing
The McGraw-Hill Companies, Inc., 2000
IP Datagram (Cont.)o Checksumo Source addressn Define the IP address of the sourcen Never changed between the trip
o Destination addressn Define the IP address of the destinationn Never changed between the trip
Example 1Example 1
An IP packet has arrived with the first 8 bits as shown:
ç 01000010
The receiver discards the packet. Why?
The McGraw-Hill Companies, Inc., 2000
o There is an error in this packeto The 4 left-most bits (0100) show the versionn which is correct
o The next 4 bits (0010) show the header lengthn which means (2 × 4 = 8), which is wrongn The minimum number of bytes in the header must
be 20n The packet has been corrupted in transmission
SolutionSolution
Example 2Example 2
In an IP packet, the value of HLEN is 1000 in binary. How many bytes of options are being carried by this packet?
The McGraw-Hill Companies, Inc., 2000
o The HLEN value is 8n The total number of bytes in the header is 8 × 4 or
32 bytes
o The first 20 bytes are the main header
o The next 12 bytes are the options.
SolutionSolution
Example 3Example 3
In an IP packet, the value of HLEN is 516and the value of the total length field is 002816. How many bytes of data are being carried by this packet?
The McGraw-Hill Companies, Inc., 2000
o The HLEN value is 5n the total number of bytes in the header is 5 × 4 or
20 bytes (no options)
o The total length is 40 bytes
o The packet is carrying 20 bytes of data (40-20)
SolutionSolution
Example 4Example 4
An IP packet has arrived with the first few hexadecimal digits as shown below:
ç 45000028000100000102...................
How many hops can this packet travel before being dropped? The data belong to what upper layer protocol?
The McGraw-Hill Companies, Inc., 2000
o To find the time-to-live field, we should skip 8 bytes (16 hexadecimal digits)
o The time-to-live field is the ninth byten Which is 01
o The packet can travel only one hopo The protocol field is the next byte (02)n The upper layer protocol is IGMP
SolutionSolution
FRAGMENTATION
8.28.2
The McGraw-Hill Companies, Inc., 2000
Maximum Transfer Unit (MTU)o Each data link layer protocol has its own
frame formatn One of this field defines the maximum size of the
data fieldo The maximum length of the IP datagramn 65,535 bytes
o Fragmentationn We must divide the IP datagram to make it
possible to pass through the underlying network
Figure 8-6
MTU
The McGraw-Hill Companies, Inc., 2000
MTUs for Different Networks
296PPP576X.25
1, 500Ethernet4, 352FDDI4, 464Token Ring (4 Mbps)
17, 914Token Ring (16 Mbps)
65,535HyperchannelMTUProtocol
Fragmentationo When a IP datagram is fragmentedn Each fragment has its own IP headern Most of the fields repeated but some changed
o A fragmented datagram may itself be fragmented n A datagram can be fragmented several times
Fragmentation (Cont.)o A datagram can be fragmented by the source
host or any router in the path
o However, the reassembly is done only by the destination hostn Each fragment becomes an independent datagram
Fragmentation (Cont.)o When a datagram is fragmentedn Router must change the values of three fields
o Flags, fragmentation offset, and total length
n Option field may or may not be copied
n The value of checksum must be recalculated regardless of fragmentation
Figure 8-2
IP Datagram
The McGraw-Hill Companies, Inc., 2000
Fields Related to Fragmentationo Identificationn 16-bit field identifies a datagram originating from
the source hostn The combination of the identification and source
IP address uniquely define a datagramn IP uses a counter to label the datagramn When fragmented, identification field is copied
into all fragmentationn All fragments have the same identification number
Fields Related to Fragmentation (Cont.)o Flags: 3-bit fieldn 1st bit: reservedn 2nd bit: called do not fragment bit
o 1: do not fragment. n If cannot pass through the physical network, router discards
the datagram and send an ICMP error message to the sourceo 0: can be fragmented if necessary
n 3rd bit: called the more fragment bito 1: the datagram is not the last fragmento 0: this is the last or only fragment
Figure 8-7
Flag Field
The McGraw-Hill Companies, Inc., 2000
Fields Related to Fragmentation (Cont.)o Fragmentation offsetn The relative position of this fragment with respect
to the whole datagram
n Measured in units of 8 bytes
n Thus, the first byte number of each fragment is divisible by 8
Figure 8-8
Fragmentation Example
The McGraw-Hill Companies, Inc., 2000
Figure 8-9
Detailed Example
The McGraw-Hill Companies, Inc., 2000
Reassemblyo The first fragment has an offset value of zeroo Divide the length of the first fragment by 8
n The second fragment has an offset value equal to that result
o Divide the total length of the first and second fragment by 8n The third fragment has an offset value equal to that result
o Continue the process until the last fragment has a more bit value 0
Example 5Example 5
A packet has arrived with an M bit value of 0. Is this the first fragment, the last fragment, or a middle fragment? Do we know if the packet was fragmented?
The McGraw-Hill Companies, Inc., 2000
o If the M bit is 0n There are no more fragmentsn The fragment is the last one
o However, we cannot say if the original packet was fragmented or not
o A nonfragmented packet is considered the last fragment
SolutionSolution
Example 6Example 6
A packet has arrived with an M bit value of 1. Is this the first fragment, the last fragment, or a middle fragment? Do we know if the packet was fragmented?
The McGraw-Hill Companies, Inc., 2000
o If the M bit is 1n There is at least one more fragment
o This fragment can be the first one or a middle one, but not the last one
o We don’t know if it is the first one or a middle one; we need more informationn The value of the fragmentation offset
o However, we can definitely say the original packet has been fragmented because the M bit value is 1
SolutionSolution
Example 7Example 7
A packet has arrived with an M bit value of 1 and a fragmentation offset value of zero. Is this the first fragment, the last fragment, or a middle fragment?
The McGraw-Hill Companies, Inc., 2000
o The M bit is 1n Either the first fragment or a middle one.
o The offset value is 0n It is the first fragment
SolutionSolution
Example 8Example 8
A packet has arrived in which the offset value is 100. What is the number of the first byte? Do we know the number of the last byte?
The McGraw-Hill Companies, Inc., 2000
o To find the number of the first byten Multiply the offset value by 8n The first byte number is 800.
o We cannot determine the number of the last byte unless we know the length of the data
SolutionSolution
Example 9Example 9
A packet has arrived in which the offset value is 100, the value of HLEN is 5 and the value of the total length field is 100. What is the number of the first byte and the last byte?
The McGraw-Hill Companies, Inc., 2000
o The first byte number is 100 × 8 = 800o The header length is 20 bytes (5 × 4)o The total length is 100 bytesn There are 80 bytes in this datagram
o If the first byte number is 800, the last byte number must 879
SolutionSolution
OPTIONS
8.38.3
The McGraw-Hill Companies, Inc., 2000
Options Formato Code field: 1-byteo Length field: 1-byten Total length of the option
o Include the code field and the length fieldn Not present in all of the option types
o Data field: variable-sizedn Contain the data that specific option requiredn Not present in all option types
Figure 8-10
Option Format
The McGraw-Hill Companies, Inc., 2000
Code Fieldo Copy: 1-bit controls the presence of the option in
fragmentationn 0: the option only appear in the first fragmentn 1: the option appear in all fragments
o Class: 2-bit defines the general purposes of the optionn 00: the option is used for datagram controln 10: the option is used for debugging and managementn 01 and 11: have not yet been defined
o Number: 5-bit defines the type of the optionn only 6 types are in use
Option Typeso Only 6 options are currently being used
o Two of them are 1-byte optionn Do not require the length or the data fields
o Four of them are multiple-byte optionn Require the length and the data fields
Figure 8-11
Categories of Options
The McGraw-Hill Companies, Inc., 2000
No Operationo Used as a filler between optionso For example, used to align the next option on
a 16-bit or 32-bit boundary
End of Optiono Used for padding at the end of the option fieldn Can only be used as the last optionn Only one end of option option can be usedn After this option
o The receiver check for the payload data
n Thus, if more than 1 byte is needed to align the option fieldo Some no operation options must be used followed by
an end of option option
End of Option (Cont.)
Record Routeo Used to record the internet routers that handle
the datagramn Can list up to nine router IP address since the
maximum size of option part in an IP header is 40 bytes
o Pointer: an offset integer field containing the byte number of the first empty entryn Point to the first available entry
Figure 8-14
Record Route Option
The McGraw-Hill Companies, Inc., 2000
Record Route (Cont.)o Initially the pointer field has a value of 4
o When receiving this datagram, the routern Insert its outgoing IP address in the empty fieldn Increment the value of the pointer by 4
Figure 8-15
Record Route Concept
The McGraw-Hill Companies, Inc., 2000
Strict Source Routeo Used by the source to predetermine a route for
the datagramo Rulen All the routers defined in the option must be
visitedn A router must not be visited if its IP address is not
listed in the datagram
Strict Source Route (Cont.)o If the datagram visits a router not on the listn Discard the datagram and issue an error message
o If the datagram arrives at the destination and some of the entries were not visitedn Discard the datagram and issue an error message
Figure 8-16
Strict Source Route Option
The McGraw-Hill Companies, Inc., 2000
Strict Source Route Operationso When a datagram arriving at a router, compare the
pointer value with the length fieldn If pointer <= length, compare the IP address pointed by the
pointer with its incoming IP addresso If equal,
n Process the packetn Overwrite the current IP address with its outgoing IP address n Increment the pointer by 4n Forward the packet
o If not equal, discard the datagram and issue an error message
n If pointer > length, discard the datagram and issue an error message
Strict Source Route Concept
Loose Source Routeo Each router in the list must be visitedo But the datagram can visit other routers as
well
Timestampo Used to record the time of datagram
processing by a routern Expressed in millisecond from midnight,
Universal Time
n Help to track the behavior of the router
Figure 8-19
Timestamp Option
The McGraw-Hill Companies, Inc., 2000
Timestamp Option Formato Overflow field
n The number of routers that could not add their timestamp because no more fields were available
o Flag: the visited router responsibilitiesn 0: each router add only timestamp in the provided fieldn 1: each router add its outgoing IP address and timestampn 3: the IP address are given. Each router check the given IP
address with its own incoming IP addresso If match, overwrite with its outgoing IP address and add timestamp
Figure 8-20
Use of Flag in Timestamp
The McGraw-Hill Companies, Inc., 2000
Figure 8-21
Timestamp Concept with Flag Value of 1
The McGraw-Hill Companies, Inc., 2000
Example 10Example 10
Which of the six options must be copied to each fragment?
The McGraw-Hill Companies, Inc., 2000
o Look at the first (left-most) bit of the code for each optionn No operation: Code is 00000001; no copy.n End of option: Code is 00000000; no copyn Record route: Code is 00000111; no copyn Strict source route: Code is 10001001; copiedn Loose source route: Code is 10000011; copiedn Timestamp: Code is 01000100; no copy
SolutionSolution
Example 11Example 11
Which of the six options are used for datagram control and which are used for debugging and management?
The McGraw-Hill Companies, Inc., 2000
o Look at the second and third (left-most) bits of the coden No operation: Code is 00000001; controln End of option: Code is 00000000; controln Record route: Code is 00000111; controln Strict source route: Code is 10001001; controln Loose source route: Code is 10000011; controln Timestamp: Code is 01000100; debugging
SolutionSolution
Example 12o One of the utilities available in UNIX to check the
travelling of the IP packets is ping.o Oing a server named fhda.edu and the result shows
that the IP address of the host is 153.18.8.1
$ ping fhda.eduPING fhda.edu (153.18.8.1) 56(84) bytes of data.64 bytes from tiptoe.fhda.edu (153.18.8.1): ....
Example 13o We can also use the ping utility with the -R
option to implement the record route option
$ ping -R fhda.eduPING fhda.edu (153.18.8.1) 56(124) bytes of data.64 bytes from tiptoe.fhda.edu (153.18.8.1): icmp_seq=0 ttl=62 time=2.70 msRR: voyager.deanza.fhda.edu (153.18.17.11)
Dcore_G0_3-69.fhda.edu (153.18.251.3)Dbackup_V13.fhda.edu (153.18.191.249) tiptoe.fhda.edu (153.18.8.1)Dbackup_V62.fhda.edu (153.18.251.34)Dcore_G0_1-6.fhda.edu (153.18.31.254) voyager.deanza.fhda.edu (153.18.17.11)
Example 14o The traceroute utility can also be used to keep
track of the route of a packet
$ traceroute fhda.edutraceroute to fhda.edu (153.18.8.1), 30 hops max, 38 byte packets
1 Dcore_G0_1-6.fhda.edu (153.18.31.254) 0.972 ms 0.902 ms 0.881 ms2 Dbackup_V69.fhda.edu (153.18.251.4) 2.113 ms 1.996 ms 2.059 ms3 tiptoe.fhda.edu (153.18.8.1) 1.791 ms 1.741 ms 1.751 ms
The result shows the three routers visited.
Example 15o The traceroute program can be used to
implement loose source routing. n The -g option allows us to define the routers to be
visited, from the source to destination.n Following shows how we send a packet to the
fhda.edu server with the requirement that the packet visit the router 153.18.251.4
$ traceroute -g 153.18.251.4 fhda.edu.traceroute to fhda.edu (153.18.8.1), 30 hops max, 46 byte packets
1 Dcore_G0_1-6.fhda.edu (153.18.31.254) 0.976 ms 0.906 ms 0.889 ms2 Dbackup_V69.fhda.edu (153.18.251.4) 2.168 ms 2.148 ms 2.037 ms
Example 16o The traceroute program can also be used to
implement strict source routing. n The -G option forces the packet to visit the
routers defined in the command line. n Following shows how we send a packet to the
fhda.edu server and force the packet to visit the router 153.18.251.4
$ traceroute -G 153.18.251.4 fhda.edu.traceroute to fhda.edu (153.18.8.1), 30 hops max, 46 byte packets1 Dbackup_V69.fhda.edu (153.18.251.4) 2.168 ms 2.148 ms 2.037 ms
CHECKSUM
8.48.4
The McGraw-Hill Companies, Inc., 2000
Checksumo Error detection methodo Checksum calculation at the sendern The packet is divided into k section, each of n bitsn All sections are added together using one’s
complement arithmeticn The final result is complemented to make the
checksum
Checksum (Cont.)o Checksum calculation at the receivern Divides the received packet, including the
checksum, into k section
n Add all section and then complement the result
n If the final result is 0, the packet is acceptedo Otherwise, reject the packet
To create the checksum the sender does To create the checksum the sender does the following:the following:
1.1. The packet is divided into k sections, The packet is divided into k sections, each of n bits.each of n bits.
2.2. All sections are added together using All sections are added together using oneone’’s complement arithmetic.s complement arithmetic.
3.3. The final result is complemented The final result is complemented to make the checksum.to make the checksum.
The McGraw-Hill Companies, Inc., 2000
Figure 8-2
IP Datagram
The McGraw-Hill Companies, Inc., 2000
Figure 8-22
Checksum Concept
The McGraw-Hill Companies, Inc., 2000
Checksum Concepto According to the one’s complement arithmeticn If all the section are added and the number is Tn Complement T in one’s complement is –Tn Thus, if the sum is T, the checksum is –T
o When the sender receives the packetn T + (-T) in one’s complement is -0n Complement -0 derive 0n Thus, the final result should be 0
Figure 8-23
Checksum in One’s Complement Arithmetic
The McGraw-Hill Companies, Inc., 2000
Checksum in the IP Packeto The checksum in the IP packet covers only
the header, not the data. This is becausen All higher-level protocols that encapsulate data in
the IP datagram have a checksum fieldo Checksum for the IP datagram do no have to check
the encapsulated datan The header of the IP datagram changes with each
visited router, but the data does noto If the data is included, each router must recalculate the
check for the whole packet and increase the overhead
Example of Checksum Calculationin Binary
Example of Checksum Calculationin Hexadecimal
IP PACKAGE
8.58.5
The McGraw-Hill Companies, Inc., 2000
IP Packageo IP package may involves following components
n Header-adding modulen Processing modulen Routing modulen Fragmentation modulen Reassembly modulen Routing modulen MTU tablen Reassembly tablen Input/output queue
o Omit the option processing module in the package
Figure 8-26
IP Components
The McGraw-Hill Companies, Inc., 2000
Header-Adding Moduleo Receives data from an upper-level protocol
and destination IP address1. Encapsulate the data in an IP datagram2. Calculate the checksum and insert it in the
checksum field3. Send the data to the corresponding input queue4. Return
Processing Moduleo The heart of the IP package
o Receive a datagram from either an interface or the header-adding module
Processing Module (Cont.)o Remove one datagram from one of the input queueso If (destination address is 127.X.Y.Z or match one of the local
address )n Send the datagram to the reassembly modulen Return
o If (machine is a router )n Decrement TTL
o If (TTL less than or equal to zero)n Discard the datagramn Send an ICMP error messagen Return
o Send the datagram to the routing moduleo Return
Queueso Input queue: n Store the datagram coming from the data link
layer or the upper-layer protocolsn Dequeued by the processing module
o Output queue: n Store the datagram going to the data link layer or
the upper-layer protocoln Enqueued by the fragmentation and reassembly
module
Routing Table, Routing Module, and MTU Tableo Routing Tablen Discussed before in Chapter 6
o Routing Modulen Discussed before in Chapter 6
o MTU Tablen Used by the fragmentation module to find the
maximum transfer unit of a particular interface
Figure 8-27
MTU Table
The McGraw-Hill Companies, Inc., 2000
Fragmentation Moduleo Receive: an IP datagram from the routing module1. Extract the size of the datagram2. If (size > MTU of the corresponding interface)
1. If [ D (do not fragment) bit is set ]1. Discard the datagram and send an ICMP error message2. Return
2. Else1. Calculate the maximum size2. Divide the datagram into fragments3. Add header to each fragment4. Add require options to each fragment5. Send the datagrams6. Return
3. Else1. Send the datagram
4. Return
Reassembly Tableo Used by the reassembly moduleo Has five fields
n State: FREE or IN-USEn Source IP address: source IP address of datagramn Datagram ID
o A number unique defines a datagram and all of the fragments belonging to that datagram
n Time-outo A predetermined amount of time in which all fragments must arrive
n Fragmentso A pointer to a linked list of fragments
Figure 8-28
Reassembly Table
The McGraw-Hill Companies, Inc., 2000
Reassembly Moduleo Receive, from the processing module, those
datagram fragments arriving at their final destinations
o Since IP is connectionlessn The fragment may arrive out of ordern Fragments may be intermixedn Use a reassembly table to keep track of these
fragments
Reassembly Module (Cont.)o Receive: an IP datagram from the processing module1. If (fragment offset value is zero and M (more fragment) bits is 0)
1. Send the datagram to the appropriate queue2. Return
2. Search the reassembly table for the entry3. If ( not found)
1. Create a new entry4. Insert the fragment at the appropriate place in the linked list
1. If (all fragments have arrived)1. Reassembly the fragments2. Deliver the datagram to the corresponding upper layer protocol3. Return
2. Else1. Check the time-out2. If (time-out expired)
1. Discard all fragments and send an ICMP error message
5. Return