Session 3 CSE 5348 / 7348 Instructor: Internetworking Protocols and Programming

Download Report

Transcript Session 3 CSE 5348 / 7348 Instructor: Internetworking Protocols and Programming

Internetworking Protocols and Programming
CSE 5348 / 7348
Instructor: Krish Pillai
Session 3
5/24/2016
Southern Methodist University
1
The Internet Protocol
• Packets are delivered between two directly connected machines using Physical
(MAC) addresses
• Sending packets across interconnected physical networks require the use of IP
addresses to specify end points
• Upper Layer protocols create messages to be sent to a specific machine
• Layer three constructs the IP datagram with proper addressing showing end points
• Layer two constructs Ethernet Frames with addresses between hops
• CSMA/CD uses electrical signaling to transport data across the link
IP (layer 3)
MAC (layer 2)
Physical (Layer 1)
NH
data
DH
NH
data
DH
NH
data
IP Datagrams
Ethernet Frames
CSMA/CD
NH = Network Header
DH = Data Link Header – RFC 1042/RFC894
5/24/2016
Southern Methodist University
2
The Internet Protocol
Inside an Ethernet Frame
0
31
4-bit
version
4-bit header
length
8-bit Type of Service
(TOS)
3-bit
flags
16-bit identification
13-bit fragment offset
20 bytes
8-bit time to live
(TTL)
16-bit total length (in bytes)
16-bit header checksum
8-bit protocol
32-bit Source IP address
32-bit Destination IP address
Options (if any)
Data
……….
5/24/2016
Southern Methodist University
3
Internetworking Protocols and Programming
• version field holds the current IP protocol number, which is 4 (IPv4)
• header-length is the number of 32-bit words in the header including any options
• type-of-service is composed of a precedence field, 4 TOS bits and an unused bit
always set to zero. TOS bits can be set to
• minimize delay
• maximize throughput
• maximize reliability, and
• minimize monetary cost
• total-length refers to the total length of the IP datagram in bytes
• identification field holds a sequence number for each datagram sent by a host
• flags field and fragmentation-offset relates to datagram fragmentation en route
5/24/2016
Southern Methodist University
4
The Internet Protocol
• time-to-live field, or TTL, limits the number of routers (hops) a
datagram can traverse (initial value of 32 or 64 decremented by each
router that forward)
• protocol field identifies the upper layer protocol that gave the
datagram to the IP layer
• header-checksum is calculated over the IP header alone
• source and destination addresses are thirty two bit words containing
the end point IP addresses
• options field is a variable-length list of information about the
datagram defining security source routing, etc. Rarely used. Always
ends on or is padded to a 32 bit boundary.
5/24/2016
Southern Methodist University
5
The Type of Service Field
0
1
2
Precedence
3
4
5
6
7
D
T
R
UNUSED
• Bit 7 and 8 are unused
• R bit when set requests high reliability
• T bit when set requests high throughput
• D bit when set requests low delay
• The network does not have to honor these requests
• Precedence field ranges for zero (normal) to 7 (network control)
• Higher number means preferential forwarding
• Eight bit Service type was redefined in the late 1990s
5/24/2016
Southern Methodist University
6
Differentiated Services
0
1
2
3
4
5
Codepoint
6
7
UNUSED
• Fully backward compatible with previous definition
• Most significant six bits comprise a codepoint
• When last three bits are zero, higher precedence number requests
preferential treatment (eight classes)
• All routers maintain at least two priority queues to handle
priorities six and seven when D-T-R is zero
Pool
Codepoint
Assigned by
1
xxxxx0
Standards Organization
2
xxxx11
Local or experimental
3
xxxx01
Temporarily in pool 2
5/24/2016
Southern Methodist University
7
Maximum Transfer Unit (MTU)
• IP allows 2^16 or 65,535 bytes as maximum length of datagram
• Lower layers may have smaller MTUs
• IP layer has to break datagram up into fragments based on MTU setting in
kernel
• Routers en route may fragment datagrams based on forward path MTU
Network
MTU (bytes)
16 Mbits/sec token ring (IBM)
17914
4 Mbits/sec token ring (IEEE 802.5)
4464
FDDI
4352
Ethernet
1500
IEEE 802.3/802.2
1492
X.25
576
Point-to-Point
296
5/24/2016
Southern Methodist University
8
Fragmentation operations
• identification field is copied into each fragment
• flags field lower order 2 bits control fragmentation
• first control bit “don’t fragment” (DF) flag when set, indicates
that packets should be dropped and not fragmented en route
• second control bit indicates that more fragments follow. All
fragments except the last one has this bit set
• fragment-offset holds the offset of the fragment in 8 octets from
the beginning of the original datagram
• total-length field of each fragment is updated to the size of the
fragment
5/24/2016
Southern Methodist University
9
Fragmentation
• Fragmentation on host is more often the norm than not
• A host is not required to receive a datagram larger than 576 bytes
• Data link will fragment datagram based on underlying technology
• Most upper Layer Protocols (ULP) limit datagram size to 512
bytes to stay within the 576 byte limit
• Routers will break up datagram if the egress link has a smaller
MTU than the ingress link
• Routers do not reassemble fragments
• Reassembly happens only at the destination point
• Packets may, and usually do arrive out of order
5/24/2016
Southern Methodist University
10
Time to Live
• Time to Live (TTL) is a field that is set up to a value (32 or 64)
by sender
• TTL indicates in “ticks” how long the packet should remain in the
network
• Each router decrements the TTL field by one when it forwards a
datagram
• Upon receiving a packet, if TTL is 0 the packet is discarded and
the sender is notified
• Routing errors can create loops in the routing scheme
• The TTL scheme prevents undeliverable packets from saturating
the network
5/24/2016
Southern Methodist University
11
Checksum
• The checksum field ensures that there are no errors introduced
into the datagram as it is forwarded
• Routers change TTL, Fragmentation, etc in the IP header
• Checksum is a signature that represents the original header was
not subject to bit errors
• Checksum is constructed by breaking up the header into 16 bit
words with the checksum field set to zero
• One’s complement addition of all the words are computed
• The checksum is the one’s complement of the result
• The resulting value is loaded into the checksum field
5/24/2016
Southern Methodist University
12
Checksum
• Consider a pseudo header consisting of 16 bits. Header is built up of four
Nibbles (nibble = 4 bits). Nibble 1 is the source address Nibble 2 is the
destination address Nibble 3 is the protocol type and Nibble four is the header
checksum. Compute the checksum for the following nibble:
1010
0111
1110
Checksum
1’s complement addition (no carry):
0101 + 1’s complement of SRC
1000 + 1’s complement of DST
0001 + 1’s complement of Protocol
1111
1’s complement of zero checksum
---0011
Sum of 1’s complements
1100
5/24/2016
1’s complement of sum = checksum
Southern Methodist University
13
Checksum
• The header shown below is accepted by a switch. Check to see if
there are errors by computing the checksum:
1010
0111
1110
1100
1’s complement addition:
0101 +
1000 +
0001 +
0011
---1111
5/24/2016
Southern Methodist University
14
IP Options
• Options allow specialized treatment of the datagram and is not required on all
transmissions
• The length of the option field depends on the option requested
• The option field is always padded to a multiple of 32 bits
• Option field are placed contiguously without special separators or delimiters
• Class specifies the general functional domain (network control, debug, etc.)
and the number specifies a specific attribute within a domain
• Copy flag controls how routers treat options during fragmentation. If set then
the options are copied into all fragments
0
Copy
1
2
Option Class
3
4
5
6
7
Option Number
Option Code Octet
5/24/2016
Southern Methodist University
15
Record Route Option
8
0
Code (7)
24
16
Length
31
Pointer
First IP address
Second IP address
...
• Regular IP datagrams do not contain information on the routers
that forwarded the datagram to its destination
• The Record Route options allows the discovery of nodes involved
in packet forwarding
• Host creates an empty list of IP addresses with
Code/Length/Pointer fields filled in
5/24/2016
Southern Methodist University
16
Record Route Option
• Length specifies the total length of the option including the first
three bytes
• Pointer specifies offset within the option indicating next available
slot in list for IP address entry
• Router adds its address to slot pointed by “Pointer” and adjust
pointer to next slot (ptr = ptr+4)
• If Pointer is greater than List, the list is deemed full and router
does not update list
• Enough space must be defined in the List at the onset
• The destination machine can use list to determine network state
5/24/2016
Southern Methodist University
17
Source Route Option
8
0
Code (137)
24
16
Length
31
Pointer
IP address of First Hop
IP address of Second Hop
...
• Copy bit is set since all fragments should follow the same route
• Allows sender to pin a path through the Internet routing fabric
• Sender creates a list of routers that the datagram should traverse
5/24/2016
Southern Methodist University
18
Source Route Option
• Sender can force datagram to touch all routers in the list and no
more by selecting Strict Source Routing
• Loose Source routing allows packet to traverse a superset of the
list allowing extra hops between entries in the list
• Option number is 9 (code = 128 + 9 = 137) for strict source
routing
• Option number is 3 (code = 128 + 3 = 131) for loose source
routing
• In both Source routing options, intermediate Routers overwrite
items in the list exactly as in Record Route option
5/24/2016
Southern Methodist University
19
Time Stamp Option
8
0
Code (68)
24
16
Length
Pointer
OFLOW
31
FLAGS
First IP address
First Timestamp
...
• Sender constructs empty list similar to Record Routed datagram
• The list contains records made up of IP address and 32 bit
timestamp
• Each router in the path adds its IP address and time when
datagram was processed
• Time is specified in milliseconds after midnight GMT
5/24/2016
Southern Methodist University
20
Timestamp Option
• If router finds Pointer greater than allowable length of list, router
increments 4 bit OFLOW field
• FLAGS control the format of the IP address/Timestamp tuple
• 0 means IP addresses are not required; 1 means both IP address
and time stamp is required
• FLAG of 3 means that the sender did not send an empty list and
that a Timestamp should only be supplied by routers specified in
the list
• If the network time is supplied from a centralized source and
closely controlled by a protocol such as NTP, the timestamp option
is a good way to measure network latency
5/24/2016
Southern Methodist University
21
Routing IP datagrams
• A router is a computer that interconnects physical networks to
form the Internet
• Routers learn from configurations and from each other how
packets bound for a certain network should be forwarded
• Routers generally have multiple network interfaces
• Hosts sink or source packets, and never forward datagrams,
unlike routers
• Transmitting packets between directly connected hosts is termed
Direct Delivery
• Transmitting packets between hosts across multiple routers is
termed Indirect Delivery
5/24/2016
Southern Methodist University
22
Next Hop Routing
• Routers build routing tables that typically contain tuple (N,R)
• N is the IP address of the destination network, and R is the IP
address of the next Hop router
• All Next Hop routers are directly connected to this router
• Routing Tables should have minimal entries for quick lookups
• The default router entry (0.0.0.0) is used if a packet is destined for a
network that has no entry in the Table
• The Router extracts the received datagram, looks up the next Hop
router in the routing Table
• The datagram and the next hop router IP address is passed to the
data link layer
• The data link layer uses ARP cache to construct an Ethernet Frame
for the next hop router and forwards the datagram
5/24/2016
Southern Methodist University
23
Next Hop Routing
• Routers have to move packets at very high speeds across multiple
interfaces
• A table lookup is therefore not feasible each time a packet comes in
since typical Routing table has room for 500 networks and 100 hosts
• To avoid repeated lookups, routers maintain a route cache called a
Forwarding Table which is unique for each interface
• Every successful routing results in the smaller cache being updated
• Typical Forwarding table is 128 entries long
• Routers decrement TTL and update the checksum in the IP header
field
• Checksum only needs to be incremented and doesn’t have to be
recomputed
5/24/2016
Southern Methodist University
24
Next Hop Routing
Software Components on a Router
Forwarding
Table
OSPF
BGP
RIP
EGP
Routing Table manager
Forwarding
Table
Forwarding
Table
Routing Table
IP Interface
Static Routes
Forwarding
Table
• One Forwarding Table per interface
• One Routing Table per Router
• Routing Table size is affected by number of networks, number of hosts
5/24/2016
Southern Methodist University
25
Internet Notifications
• Communication of error messages or other conditions that require
attention is done using the ICMP protocol (RFC 792)
• ICMP stands for Internet Control and Message Protocol
• ICMP is considered the same layer as IP (Layer 3) since there are
no ports associated with this protocol
• Each message is identified by a type and code field that uniquely
identifies the contents of the ICMP message
7 8
0
8-bit type
15 16
8-bit code
31
16-bit checksum
Contents depend on type and code
5/24/2016
Southern Methodist University
26
ICMP
• ICMP messages are of two types – Errors and Queries
• Query messages are sent to request information about a remote
machine
• Error messages are generated by a machine to notify the
corresponding machine of an undesirable condition
• When an ICMP error message is sent, the IP header and the next
eight bytes of the ULP header is carried in the message
• TCP/UDP port numbers are held in the eight bytes of the Transport
Layer header
• This information sent back from the error detecting node helps the
receiving ULP analyze the cause of the error
5/24/2016
Southern Methodist University
27
ICMP Message Format
Type Field
5/24/2016
ICMP Message Type
0
Echo reply
3
Destination Unreachable
4
Source Quench
5
Redirect (change a route)
8
Echo Request
9
Router Advertisement
10
Router Solicitation
11
Time Exceeded for a Datagram
12
Parameter Problem on a Datagram
13
Timestamp Request
14
Timestamp Reply
15
Information Request (obsolete)
16
Information Reply (obsolete)
17
Address Mask Request
18
Address Mask Reply
Southern Methodist University
28
ICMP Messages (Ping)
• ICMP echo request/reply messages are used to check if a node is
active on the network
• Any machine receiving an ICMP Echo request (8) responds with a
reply (0)
• User layer program “ping” generates ECHO request given an IP
address and prints out received responses
8
0
Type (0 or 8)
16
31
Code (0)
Checksum
IDENTIFIER
SEQUENCE NUMBER
OPTIONAL DATA
...
5/24/2016
Southern Methodist University
29
ICMP Messages (Undeliverable)
• When a router cannot forward a packet to its destination for various reasons it
generates a destination unreachable message
• Various code values indicate the reason why the packet is being discarded
• Network/host
unreachable
• Protocol/Port unreachable
• Could not fragment
• Administrative block on routing
• blocked type of service
• Source route failed
8
0
Type (3)
16
Code (0 - 12)
31
Checksum
UNUSED (Must be zero)
Internet Header + First 64 Bits of Datagram
...
5/24/2016
Southern Methodist University
30
ICMP Messages (Source Quench)
• Routers enqueue packets while they are taking forwarding decisions across
multiple ports
• Heavy traffic can cause the buffers to overflow causing packet loss
• When a router detects network congestion (increasing queue length) it can send a
Source Quench Message to the sender
• Source Quench has the affect of reducing the rate at which the sender injects
packets into the network
8
0
Type (4)
16
Code (0)
31
Checksum
UNUSED (Must be zero)
Internet Header + First 64 Bits of Datagram
...
5/24/2016
Southern Methodist University
31
ICMP Messages (Redirect)
• Hosts generally send packets outside their physical networks by forwarding it to
the router
• Hosts may erroneously or by design send a packet to a router due to
configuration
• A router can then send a Route change request to the host causing it to forward all
subsequent packets to the new router address supplied in the message
• Routers in addition forward the packet that generated the ICMP redirect message
without dropping it
• Networks with multiple routers, wrongly configured masks on host, etc. trigger
redirect messages
8
0
Type (5)
16
Code (0 to 3)
31
Checksum
Router IP address
Internet Header + First 64 Bits of Datagram
...
5/24/2016
Southern Methodist University
32
ICMP Messages (Time Exceeded)
• Badly configured routers can set up routing loops on the Internet
• Loops can cause packets to circulate between routers
• When a router forwards a packet it decrements TTL
• If TTL drops to zero, router discards packet and generates an ICMP
“Time exceeded in transit” message (Code 0)
• Code 1 indicates that the Host timed out waiting for a fragment to
arrive
8
0
Type (11)
16
Code (0 to 1)
31
Checksum
UNUSED (Must be Zero)
Internet Header + First 64 Bits of Datagram
...
5/24/2016
Southern Methodist University
33
ICMP Messages (Time stamp)
• ICMP Time stamp request can be sent to a machine to solicit a
response
• The reply will contain the originating, received and transmitted
timestamps in milliseconds since midnight
• Sender fills in “Originate field” and leaves other two fields empty
• Receiver fills in the “Receive” field when accepting the packet and
the transmit field before the packet is finally sent out
8
0
Type (13 or 14)
IDENTIFIER
16
31
Code (0)
Checksum
Sequence Number
Originate Timestamp
Receive Timestamp
Terminate Timestamp
5/24/2016
Southern Methodist University
34
ICMP Messages (Subnet Mask)
• A host can get the subnet mask of the local network by sending out
an address mask request to a router or to the broadcast address
• The reply from the router will contain the subnet mask defined for
that physical network
8
0
Type (17 or 18)
16
Code (0)
31
Checksum
Sequence Number
IDENTIFIER
Address mask
5/24/2016
Southern Methodist University
35
ICMP Messages (Router Discovery)
• A router can periodically address its IP address to all hosts on the network using
the ICMP Router Advertisement message
• Default routers are sometimes configured statically on Hosts
• Dynamic configuration requires hosts maintain a soft state (Lifetime = 30min)
• Router Advertisements are made every 10 minutes Usually sent to all systems IP
address 224.0.0.1 (or broadcast)
8
0
Type (9)
NUM ADDRS
16
Code (0)
ADDR SIZE (1)
31
Checksum
Lifetime
Router Address 1
Preference Level 1
More Address/Preference tuples ….
Address Size is in 32 bit units
5/24/2016
Southern Methodist University
36
ICMP Messages (Router Solicitation)
• A host that is booted right after a router advertisement has been sent
will have to wait for the next advertisement before it can configure
itself
• Booting hosts send out Router Solicitation messages to the all
Routers IP address 224.0.0.2 (or limited broadcast)
• Router Solicitations force the router to skip periodicity and send
out a Router Advertisement immediately
8
0
Type (10)
16
Code (0)
31
Checksum
RESERVED
Address Size is in 32 bit units
5/24/2016
Southern Methodist University
37
ICMP Messages (Parameter Problem)
• A router or host that finds a problem datagram not covered by
previous Error messages will generate a “Parameter Problem”
message
• Error generated if Fields are incorrectly filled or argument counts
are inconsistent
• POINTER field indicates the location of the octet that caused the
error condition when Code is 0
• Code 1 indicates that a required option is missing when the
POINTER cannot be used to reveal the field
8
0
Type (12)
POINTER
16
Code (0 or 1)
31
Checksum
Unused (Must be Zero)
Internet Header + First 64 Bits of Datagram
...
5/24/2016
Southern Methodist University
38
Homework 2 (Due Sept 20)
• Text Book Internetworking with TCP/IP Volume I
• Read book up to Chapter 9
• Work out and submit the following 12 exercises:
2.6, 2.7
5.4, 5.9
7.1, 7.8, 7.13
8.9, 8.11
9.4, 9.7, 9.10
5/24/2016
Southern Methodist University
39