1 Chapter 8 Internet Protocol (IP) Chapter 8 Internet Protocol (IP) Mi-Jung Choi Dept. of Computer Science and Engineering
2 8.1 DATAGRAM 8.2 FRAGMENTATION 8.3OPTIONS 8.4CHECKSUM 8.5IP PACKAGE 8.6KEY TERMS 8.7 SUMMARY Contents
3 Objectives o Upon completion you will be able to: Understand the format and fields of a datagram Understand the need for fragmentation and the fields involved Understand the options available in an IP datagram Be able to perform a checksum calculation Understand the components and interactions of an IP package
4 Position of IP in TCP/IP protocol suite
5 Internet Protocol (IP) oPacket delivery mechanism in TCP/IP oUnreliable connectionless datagram protocol Each datagram handled independently Each datagram can follow a different route to destination. datagrams sent by same source and destination could arrive out of order oBest effort delivery oNo error checking or tracking
6 A packet in the IP layer is called a datagram, a variable-length packet consisting of two parts: header and data. The header is 20 to 60 bytes in length and contains information essential to routing and delivery 8.1 IP Datagram
7 oVersion(VER) 4BIT field Currently, the version is 4 oHeader Length(HLEN) 4BIT field The total length of the datagram header in 4byte words No options : 5(5*4=20), with maximum option size : 15(15*4=60) 8.1 DATAGRAM
8 oDifferentiated Services (formerly Service Type): 8bits 1. Service type The first 3bit : precedence bit Precedence l 1(000) to 7(111) l The priority of the datagram (congestion) l Not used in version routine 001 Priority 010 Immediate 011 Flash 100 Flash override 101 Critical 110 Internetwork control 111 Network control TOS Bits Description 0000 Normal (default) 0001 Minimize cost 0010 Maximize reliability 0100 Maximize throughput 1000 Minimize delay The precedence subfield was designed, but never used in version 4.
9 Table 8.2 Default types of service ProtocolTOS Bits Description ICMP 0000 Normal BOOTP 0000 Normal NNTP 0001 Minimize cost IGP 0010 Maximize reliability SNMP 0010 Maximize reliability TELNET 1000 Minimize delay FTP (data) 0100 Maximize throughput FTP (control) 1000 Minimize delay TFTP 1000 Minimize delay SMTP (command) 1000 Minimize delay SMTP (data) 0100 Maximize throughput DNS (UDP query) 1000 Minimize delay DNS (TCP query) 0000 Normal DNS (zone) 0100 Maximize throughput
DATAGRAM 2. Differentiated Services First 6bit : code point Last 2bit : not used The codepoint subfield can be used in two different ways 1.When the 3bit right-most bits are 0s, the 3bit left-most bits are interpreted the same as the precedence bits in the Service Type Interpretation 2.When the 3bit right-most bits are not all 0s, the 6bits define 64 services based on the priority assignment Temporary or experimentalXXXX013 LocalXXXX112 InternetXXXXX01 Assignment AuthorityCodepointCategory
DATAGRAM (cont.) oTotal length The total length field defines the total length of the datagram including the header. Total length of the IP datagram in byte(header + data) l Length of data = total length – HLEN l Maximum size : bytes (2 16 – 1) l Encapsulation is needed to transfer datagram in some case (some padding added)
DATAGRAM (cont.) oIdentification Used in fragmentation oFlags. Used in fragmentation oFragmentation offset Used in fragmentation fragmentation
DATAGRAM (cont.) oTime to live Datagram should have a limited lifetime l Decremented by each visited router l Discarded when zero l All the machine must have synchronized clocks and how long it takes for a datagram to go from one machine to another Cases l Corrupted router l Intentionally limit the journey of the packet
DATAGRAM(cont.) oProtocol Define the higher level protocol that uses the services of the IP layer. l Encapsulate data from several higher level protocol(TCP,UDP,ICMP,IGMP) l Specify the final destination protocol to which datagram should be delivered Value Protocol 1 ICMP 2 IGMP 6 TCP 8 EGP 17 UDP 41 IPv6 89 OSPF
DATAGRAM (cont.) oChecksum Later present oSource IP address Define the IP address of the source oDestination IP address Define the IP address of the destination
16 Example 1 : Example 1 : An IP packet has arrived with the first 8 bits as shown: The receiver discards the packet. Why? There is an error in this packet. The 4 left-most bits (0100) show the version, which is correct. The next 4 bits (0010) show the header length, which means (2 4 8), which is wrong. The minimum number of bytes in the header must be 20. The packet has been corrupted in transmission. Example 2 : Example 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 HLEN value is 8, which means the total number of bytes in the header is 8 4 or 32 bytes. The first 20 bytes are the main header, the next 12 bytes are the options. 8.1 DATAGRAM (cont.)
17 Example 3 : Example 3 : In an IP packet, the value of HLEN is 5 16 and the value of the total length field is How many bytes of data are being carried by this packet? The HLEN value is 5, which means the total number of bytes in the header is 5 4 or 20 bytes (no options). The total length is 40 bytes, which means the packet is carrying 20 bytes of data (40 20). Example 4 : Example 4 : An IP packet has arrived with the first few hexadecimal digits as shown below: How many hops can this packet travel before being dropped? The data belong to what upper layer protocol? To find the time-to-live field, we should skip 8 bytes (16 hexadecimal digits). The time-to-live field is the ninth byte, which is 01. This means the packet can travel only one hop. The protocol field is the next byte (02), which means that the upper layer protocol is IGMP. 8.1 DATAGRAM (cont.)
FRAGMENTATION oThe format and size of a frame depend on the protocol used by the physical network. A datagram may have to be fragmented to fit the protocol regulations. o The topics discussed in this section include: Maximum Transfer Unit (MTU) Fields Related to Fragmentation router Ethernet formatted frame Token ring formatted frame Ethernet network Token ring network
FRAGMENTATION oMaximum Transfer Unit (MTU) Maximum size of the data field l The total size of encapsulated datagram in a frame must be less than maximum size l Differ from one physical network protocol to another IP datagram
FRAGMENTATION - MTUs for different network - Table 8.5 MTUs for some networks
FRAGMENTATION oFragmentation Divide the datagram to make it possible to pass some networks l Each fragment has its own header – With most of the fields repeated, but some changed l A datagram can be fragmented several times l Only final destination can reassembly of the datagram l Required parts of the header must be copied by all fragments l Three fields(flags, fragmentation offsets, total length) changed
FRAGMENTATION oFields related to fragmentation Identification(16bits) l Identify a datagram originating from the source host l Combination of the identification and source IP address must be unique l IP protocol uses positive number counter(guarantee uniqueness) – Kept in the Main Memory l All fragment of a datagram have the same identification number
FRAGMENTATION Flags (3bits) l First bit : reserved l Second bit : do not fragment – 1 : must not fragment the datagram – If cannot pass the datagram through any physical network, discards the datagram and return ICMP error message to source host – 0 : the datagram can be fragmented if necessary l Third bit : more fragment – 1 : more fragments after this one – 0 : last or only fragment
FRAGMENTATION oFragmentation offset (13bits) Relative position of fragment with respect to the whole datagram Offset of the data in the original datagram measured in units of eight bytes (The size of first fragment is divisible by eight) Reassemble step in final destination host: l First fragment offset value is 0. l Divide the length of 1st fragment by 8. This value is the offset value of 2nd fragment. l Divide the length of 2st fragment by 8. This value is the offset value of 3rd fragment. l Continue the process. The last fragment has more bit value of 0.
FRAGMENTATION (cont.) Fragmentation example
FRAGMENTATION (cont.)
27 Example 5 : Example 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? If the M bit is 0, it means that there are no more fragments; the fragment is the last one. However, we cannot say if the original packet was fragmented or not. A nonfragmented packet is considered the last fragment. Example 6 : Example 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? If the M bit is 1, it means that there is at least one more fragment. This fragment can be the first one or a middle one, but not the last one. We don’t know if it is the first one or a middle one; we need more information (the value of the fragmentation offset). However, we can definitely say the original packet has been fragmented because the M bit value is FRAGMENTATION (cont.)
28 Example 7 : Example 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? Because the M bit is 1, it is either the first fragment or a middle one. Because the offset value is 0, it is the first fragment. Example 8 : Example 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? To find the number of the first byte, we multiply the offset value by 8. This means that the first byte number is 800. We cannot determine the number of the last byte unless we know the length of the data. Example 9 : Example 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 first byte number is 100 8 800. The total length is 100 bytes and the header length is 20 bytes (5 4), which means that there are 80 bytes in this datagram. If the first byte number is 800, the last byte number must FRAGMENTATION (cont.)
Options The header of the IP datagram is made of two parts: a fixed part and a variable part. The variable part comprises the options that can be a maximum of 40 bytes. o The header of the IP datagram is made of two parts: a fixed part and a variable part. The variable part comprises the options that can be a maximum of 40 bytes. The topics discussed in this section include: o The topics discussed in this section include:Format Option Types
OPTIONS oSecurity, Source routing, Record route, Timestamp oUsed for network testing and debugging oNot required for every datagram oTLV (Type, Length, Value) Format
OPTIONS oCode (8bits) : Type Copy(1bit) l Control the presence of the option in fragmentation – 0 : only copied to the first fragment – 1 : coped to all fragments Class(2bits) l General purpose of the option – 00 : datagram control – 10 : debugging and management(01& 11 not defined) Number(5bits) l Type of the option(only six types are in use) oLength Total length of the option(including code and length fields) Not present in all of the option types oData : Value The data that specific options require Not present in all of the option types
OPTIONS oOption types(6 types) Two types l 1 byte l Do not require the length or the the data fields Four types l Multiple bytes l Require the length and the data fields
OPTIONS (cont.) oNo Operation (00001) 1 byte option Used as a filler between options
OPTIONS (cont.) oEnd of Option (00000) 1 byte option Used for padding at the end of the option field Only one end of option can be used Search payload(data) after option
OPTIONS (cont.) o 경로 기록 - Record Route(00111) Used to record the internet routers that handle the datagram Nine router IP can be contained(4byte×9 = 36 bytes ≤ 40bytes) Uses a pointer field containing the byte number of the first empty entry l Initialized by 4 and increased by 4 until over the length value
OPTIONS (cont.)
37 oStrict Source Route (01001) Used by the source to predetermine a rout for the datagram All of the routers defined in the option must be visited by datagram If the datagram visits a router that is not on the list, the datagram is discarded and an error message is issued If the datagram arrives at the destination and some of the entries were not visited, it is also discarded and an error message issued
OPTIONS (cont.) Strict source route concept
OPTIONS (cont.) oLoose Source Route(00011) Similar to the strict source route Each router in the list must be visited, but the datagram can visit other routers
OPTIONS(cont.) oTimestamp(00101) Used to record the time of datagram processing by a router l Milliseconds from midnight, Universal Time Overflow field l Records the number of routers that could not add their timestamp because of no more fields available Flags field l Specify the visited router responsibilities
OPTIONS (cont.) Use of flag in timestamp -0 : add only the timestamp in the provided field -1 : add each router’s outgoing IP address and the timestamp -3 : each router must check the given IP address with its own incoming IP address If matched, the router overwrites the IP address with its outgoing IP address and adds the timestamp
OPTIONS (cont.) Timestamp concept
43 Example 10: Which of the six options must be copied to each fragment? We look at the first (left-most) bit of the code for each option. No operation: Code is ; no copy. End of option: Code is ; no copy. Record route: Code is ; no copy. Strict source route: Code is ; copied. Loose source route: Code is ; copied. Timestamp: Code is ; no copy. Example 11 : Which of the six options are used for datagram control and which are used for debugging and management? We look at the second and third (left-most) bits of the code. No operation: Code is ; control. End of option: Code is ; control. Record route: Code is ; control. Strict source route: Code is ; control. Loose source route: Code is ; control. Timestamp: Code is ; debugging 8.3 OPTIONS (cont.)
44 One of the utilities available in UNIX to check the travelling of the IP packets is ping. In the next chapter, we talk about the ping program in more detail. In this example, we want to show how to use the program to see if a host is available. We ping a server at De Anza College named fhda.edu. The result shows that the IP address of the host is $ ping fhda.edu PING fhda.edu ( ) 56(84) bytes of data. 64 bytes from tiptoe.fhda.edu ( ):.... The result shows the IP address of the host and the number of bytes used. Example 12
45 We can also use the ping utility with the -R option to implement the record route option. $ ping -R fhda.edu PING fhda.edu ( ) 56(124) bytes of data. 64 bytes from tiptoe.fhda.edu ( ): icmp_seq=0 ttl=62 time=2.70 ms RR: voyager.deanza.fhda.edu ( ) Dcore_G0_3-69.fhda.edu ( ) Dbackup_V13.fhda.edu ( ) tiptoe.fhda.edu ( ) Dbackup_V62.fhda.edu ( ) Dcore_G0_1-6.fhda.edu ( ) voyager.deanza.fhda.edu ( ) The result shows the interfaces and IP addresses. Example 13
46 The traceroute utility can also be used to keep track of the route of a packet. $ traceroute fhda.edu traceroute to fhda.edu ( ), 30 hops max, 38 byte packets 1 Dcore_G0_1-6.fhda.edu ( ) ms ms ms 2 Dbackup_V69.fhda.edu ( ) ms ms ms 3 tiptoe.fhda.edu ( ) ms ms ms The result shows the three routers visited. Example 14
47 The traceroute program can be used to implement loose source routing. The -g option allows us to define the routers to be visited, from the source to destination. The following shows how we can send a packet to the fhda.edu server with the requirement that the packet visit the router $ traceroute -g fhda.edu. traceroute to fhda.edu ( ), 30 hops max, 46 byte packets 1 Dcore_G0_1-6.fhda.edu ( ) ms ms ms 2 Dbackup_V69.fhda.edu ( ) ms ms ms Example 15
48 The traceroute program can also be used to implement strict source routing. The -G option forces the packet to visit the routers defined in the command line. The following shows how we can send a packet to the fhda.edu server and force the packet to visit only the router , not any other one. $ traceroute -G fhda.edu. traceroute to fhda.edu ( ), 30 hops max, 46 byte packets 1 Dbackup_V69.fhda.edu ( ) ms ms ms Example 16
CheckSum The error detection method used by most TCP/IP protocols is called the checksum. The checksum protects against the corruption that may occur during the transmission of a packet. It is redundant information added to the packet. o The error detection method used by most TCP/IP protocols is called the checksum. The checksum protects against the corruption that may occur during the transmission of a packet. It is redundant information added to the packet. oThe topics discussed in this section include: Checksum Calculation at the Sender Checksum Calculation at the Receiver Checksum in the IP Packet
CheckSum in IP oTo create the checksum the sender does the following: 1. The packet is divided into k sections, each of n bits. 2. All sections are added together using one’s complement arithmetic. 3. The final result is complemented to make the checksum. oChecksum in one’s complement arithmetic
51 Checksum concept
52 An example of IP header checksum calculation in binary and hexadecimal
53 Check Appendix C for a detailed description of checksum calculation and the handling of carries. Note:
54 Modulo 2 Arithmetic | / x x x x Mod Binary
IP PACKAGE We give an example of a simplified IP software package to show its components and the relationships between the components. This IP package involves eight modules. The topics discussed in this section include: Header-adding module Processing module Routing module Fragmentation module Reassembly module Routing table MTU table Reassembly table
IP PACKAGE
57 Header-adding module Receive : data, destination address 1. Encapsulate the data in an IP datagram 2.Calculate the checksum and insert it in the checksum field 3. Send the data to the corresponding input queue 4. Return
IP PACKAGE Processing module Remove one datagram from one of the input queues If(destination address is 127.X.Y.Z or matches one of the local addresses) Send the datagram to the reassembly module Return If(machine is a router) Decrement TTL If(TTL less than or equal to zero) Discard the datagram Send an ICMP error message Return Send the datagram to the routing module Return
IP PACKAGE Fragmentation module Receive : an IP datagram from the routing module 1. Extract the size of the datagram 2. If(size > MTU of the corresponding network) 1. If(D(do not fragment) bit is set) 1. Discard the datagram 2. Send an ICMP error message 3. Return 2. Else 1. Calculate the maximum size 2. Divide the datagram into fragments 3. Add header to each fragment 4. Add required options to each fragment 5. Send the datagrams 6. Return 3. Else 1. Send the datagram 4. Return MTU table
IP PACKAGE Reassembly table Used by the reassembly module Five field - State(FREE or IN-USE) - Source IP address(source IP of the datagram) - Datagram ID(uniquely define a datagram) - Time-out(predetermined amount of time, in which all fragments must arrive) - Fragments(a pointer to a linked list of fragments)
IP PACKAGE (cont.) Reassembly module Receive : an IP packet from the processing module 1.If (offset value is zero and the M bit is 0) 1. Send the datagram to the appropriate queue 2. Return 2. Search the reassembly table for the corresponding entry 3. If (not found) 1. Create a new entry 4. Insert the fragment at the appropriate place in the linked list 1. if (all fragments have arrived) 1. Reassemble the fragments 2. Deliver the datagram to the corresponding upper layer protocol 3. Return 2. Else 1. Check the time-out 2. if (time-out expired) 1. Discard all fragment 2. Send an ICMP error message 5.Return