Download - Network Layer and IP

Transcript
Page 1: Network Layer and IP

Network Layer and IP

CSC 343·643WAKE FORESTU N I V E R S I T Y

Department of Computer Science

Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 1

Network Layer

• Concerned with getting packets from the source to the destination

• In contrast, the data-link layer

– Moves frames from one end of the wire to another

– Assume everyone is locally connected

• Network layer deals with end-to-end transmission

– Routing packets (or datagrams) from one machine to

another until destination is reached

Token passing required forwarding a frame from one machine toanother, is this routing?

E. W. Fulp Fall 2009

Page 2: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 2

Network Layer Issues

B

R3

R1

R2

R4

A

D C

Host

Router

• Routing

– Given different paths, which should be taken?

– Should every packet take the same route?

• Congestion control

– Prevent a link (router) from becoming overwhelmed

• Internetworking

– Interconnect different networks at the network level

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 3

Network Layer Designs

1. Connectionless (Internet community argument)

• Network viewed as unreliable

• Hosts perform error control, flow control, and packet ordering

• Each packet sent independently

– Routes taken may change over time

Why would a route change? Implications of multiple routes?

B

R3

R1

R2

R4

A

D C

Host

Router

E. W. Fulp Fall 2009

Page 3: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 4

2. Connection-oriented (Telephone company argument)

• Network should be reasonably reliable

• Path established before packets sent

– Negotiate resources (QoS) at each hop

Any advantages to establishing a path?

B

R3

R1

R2

R4

A

D C

Host

Router

Any disadvantages to establishing a path?

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 5

Network Layer in the Internet

• Internet can be viewed as a set of connected Autonomous Systems

Central andSouth America

International

links

NorthAmerica

Asiaand thePacific

Europe

Core backbone

Continental backbones

Regional/national networks/internetworks

Global internetwork

Access networks

The global Internet

= hosts

= access network gateways

= Internet routers

E. W. Fulp Fall 2009

Page 4: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 6

• The network layer is what allows the pieces to interconnect

• The Internet Protocol (IP) provides

1. Best Effort (BE) transport of datagrams

– Unreliable service

– Packets may arrive out of order, if at all...

– No Quality of Service (QoS) guarantees provided

2. Routing from source to destination

– Can route to different AS

– Routes can change based on network conditions

Is IP connectionless or connection-oriented?

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 7

Internet Operation Overview

R1

ETH FDDI

IPIP

ETH

TCP R2

FDDI PPP

IP

R3

PPP ETH

IP

H1

IP

ETH

TCP

H8

R2

R1

H4

H5

H3H2H1

Network 2 (Ethernet)

Network 1 (Ethernet)

H6

Network 3 (FDDI)

Network 4(point-to-point)

H7 R3 H8

• Network layer takes data streams and breaks into datagrams

– Datagram can be up to 64KB each, average is 1500 bytes

• Each datagram is transmitted through the Internet

– Possibly fragmented

• Pieces arrive at destination, reassembled into original datagram

• Datagram is passed to the transport layer

E. W. Fulp Fall 2009

Page 5: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 8

IP Protocol Datagrams

• Datagram (packet) consists of a header part and data part

• Header consists of: 20 byte fixed part and an optional part

Version IHL Type of service Total length

Identification

Time to live Protocol

Fragment offset

Header checksum

Source address

Destination address

Options (0 or more words)

DF

MF

32 Bits

• Big endian order (left → right) also called network byte order

– SPARC is big endian, while Pentium is little endian

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 9

IP Header: Version and IHL Fields

• Version field (4 bits)

– Identifies the version of IP (e.g. IPv4 or IPv6)

• Internet Header Length (IHL, 4 bits)

– Total length of the IP header, in measured 32-bit words

– Minimum value is 5 (no options are present)

– Maximum value is 15, which is a byte header

– This will limit the usefulness of some options

E. W. Fulp Fall 2009

Page 6: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 10

IP Header: ToS Field

Type of Service (ToS) is 8 bits

• Indicates the type of service expected, has sub-fields

1. First three bits are the precedence (priority) sub-field

– Range from 0 (normal) to 7 (control packet)

– “which is ignored today” - Stevens

2. Next four bits request different types of service

Application

Min

Delay

Max

Throughput

Max

Reliability

Min

Cost

Hex

Value

Telnet 1 0 0 0 0x10

FTP data 0 1 0 0 0x08

SNMP 0 0 1 0 0x04

3. One unused bit

• ToS feature is not supported by most IP implementations

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 11

IP Header: Total Length and Fragmentation Fields

• Total length field (16 bits)

– Datagram length (header and data), measured in bytes

What is the maximum size of an IP datagram?

• Identification field (16 bits)

– Identifies which datagram the fragment belongs to

– One number for all the fragments of a packet

• DF (Don’t Fragment) 1 bit, if set then don’t fragment

• MF (More Fragments) 1 bit, set if not last fragment

• Fragment offset (13 bits)

– Where in the current datagram this fragment belongs

– Fragments must be a multiple of 8 bytes (except for last one)

E. W. Fulp Fall 2009

Page 7: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 12

IP Fragmentation and Reassembly

• Different network technologies have different packet sizes

– Every network has a Maximum Transmission Unit (MTU)

– If the datagram is larger than the MTU, then it is fragmented

• “Every internet module must be able to forward a datagram of 68

octets without further fragmentation... Every internet destination

must be able to receive a datagram of 576 octets either in one

piece or in fragments to be reassembled.” - [RFC791]

R2

R1

H4

H5

H3H2H1

Network 2 (Ethernet)MTU = 1500 bytes

Network 1 (Ethernet)

H6

Network 3 (FDDI)MTU = 4500 bytes

Network 4(point-to-point)

MTU = 532 bytes

H7 R3 H8

H1 R1 R2 R3 H8

ETH IP (1400) FDDI IP (1400) PPP IP (512)

PPP IP (376)

PPP IP (512)

ETH IP (512)

ETH IP (376)

ETH IP (512)1420 bytes total payload(IP header is 20 bytes)

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 13

• Assume R2 has a MTU (data) of 532 bytes (allows a 20 byte

header and 512 bytes of data)

• The original 1420 byte datagram fragmented into 3 pieces at R2

Ident = x Offset = 0

Start of header

1

Rest of header

512 data bytes

Ident = x Offset = 512

Start of header

1

Rest of header

512 data bytes

Ident = x Offset = 1024

Start of header

0

Rest of header

376 data bytes

Ident = x Offset = 0

Start of header

0

Rest of header

1400 data bytes

Original Datagram Datagram Fragmented

• RFC 1191 gives some example MTU sizes, based on the link layer

E. W. Fulp Fall 2009

Page 8: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 14

IP Header: TTL and Protocol Fields

• Time To Live (TTL, 8 bits)

– Counter to limit packet lifetime

– Maximum lifetime of packet (in seconds)

What is the maximum maximum lifetime?

– Time spent at every router is subtracted

– Actually decremented once per hop

– Once zero is reached, a control packet is sent back

What problem does TTL attempt to prevent?

• Protocol field (8 bits)

– Which transport process the packet belongs to (e.g. TCP or

UDP) numbers are global defined in [RFC 1700]

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 15

IP Header: Checksum and Address Fields

• Header checksum (16 bits)

– Verifies only the header

– Add all 16 bit words (one’s complement) then take the one’s

complement of the sum

A new checksum is computed and stored in the header atevery hop, why?

What happens if an error is detected?

How is the data verified? Do we care at this layer?

• Source and destination addresses

– 32 bits each, more later...

E. W. Fulp Fall 2009

Page 9: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 16

IP Header: Options Field

• Allow subsequent versions of IP to include new features

• Option begins with a one byte idenfication code, 5 are defined

1. Security - Security and handling restrictions [RFC1108]

If set, helps a sniffer identify the more interesting datagrams

2. Strict source routing - Gives path to follow (security issue? )

3. Loose source routing - List routers not to be missed

4. Record route - Make every router append IP address

Why is this no longer useful?

5. Timestamp - Make every router append address and time

• Options field padded out to end on 32 bit boundary

• “these options are rarely used and not all hosts and routers

support all the options” - Stevens

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 17

IPv4 Addresses

Every host or router (actually interface) has a unique IP address

• IP addresses are 32 bits long (IP version 4) and are used

in the source and destination fields of the IP datagram

• Dotted-decimal notation is used to represent each address, each

byte is represented via a decimal number

– 193.32.216.9 ⇒ [11000001 00100000 11011000 00001001]

The data link layer also has an address, what is the difference?Why is a network address needed?

• Addresses are hierarchical and encode two numbers,

network and host

E. W. Fulp Fall 2009

Page 10: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 18

IP Network Example

Consider one router and seven hosts (one address per interface)

223.1.3.27

223.1.3.2

223.1.2.9

223.1.3.1

223.1.2.1

223.1.2.2

223.1.1.4

223.1.1.1 223.1.1.2 223.1.1.3

• Three hosts at bottom have similar addresses, 223.1.1.x

– The leftmost 24 bits they share is the network portion

– Remaining 8 bits is the host portion

How many hosts can connect to the 223.1.1.x network?

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 19

• Hosts of 223.1.1.x form a network, interconnected via a LAN

– The network address is 223.1.1.0/24

– The /24 is also called the network mask or network prefix

∗ Indicates the 24 leftmost bits define the network address

– Any additional host that would attach to this network must

have a unique address of the form 223.1.1.x

• The remaining networks have a similar structure

223.1.3.0/24 223.1.2.0/24

223.1.1.0/24

E. W. Fulp Fall 2009

Page 11: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 20

Multiple IP Networks

IP definition of a network is not restricted to Ethernet segments

• Consider three routers interconnected via point-to-point links

223.1.8.1 223.1.8.0

223.1.7.1

223.1.7.0223.1.9.2

223.1.9.1

223.1.1.1 223.1.1.4

223.1.1.3

223.1.3.27

223.1.3.1

223.1.3.2

223.1.2.6

223.1.2.1

223.1.2.2

R1

R2R3

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 21

• Each router has three interfaces

– One for each point-to-point link

– One for the broadcast link to the hosts

• What are the networks in the diagram

– Three networks interconnecting hosts,

223.1.1.0/24, 223.1.2.0/24, and 223.1.3.0/24

– Three additional networks that interconnect routers

∗ 223.1.7.0/24 connects R1 ⇔ R2

∗ 223.1.8.0/24 connects R2 ⇔ R3

∗ 223.1.9.0/24 connects R3 ⇔ R1

• How do we determine what is a network

– Detach each interface from host or router

– Resulting islands are the networks

E. W. Fulp Fall 2009

Page 12: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 22

IPv4 Address Classes

The original Internet architecture defined 5 different IP address classes

• This is also know as classful addressing

• Classes differ on how bits are divided (network versus host)

32 Bits

Range of hostaddresses

1.0.0.0 to127.255.255.255

128.0.0.0 to191.255.255.255

192.0.0.0 to223.255.255.255

224.0.0.0 to239.255.255.255

240.0.0.0 to247.255.255.255

Class

0 Network Host

10 Network Host

110 Network Host

1110 Multicast address

11110 Reserved for future use

A

B

C

D

E

• This creates 3 different classes of networks (A, B, and C)

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 23

• For example, consider class A addresses

32 Bits

1.0.0.0 to127.255.255.2550 Network HostA

– First bit is zero, identifies class A

– Next 7 bits identify the network

– Last 24 bits identify the host (interface) in the class A network

• In comparison, class B has

32 Bits

128.0.0.0 to191.255.255.25510 Network HostB

What class is 223.1.1.0/24? As a company, would you preferan A, B, or C address?

E. W. Fulp Fall 2009

Page 13: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 24

IP Addresses with Special Meanings

This host

A host on this network

Broadcast on the local network

0

Host

Network

127 (Anything)

Broadcast on a distant network

Loopback

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

0 0 0 0. . .

. . .1 1 1 1 1 1 1 1

• 0.0.0.0 only used by a host when booting

• All zeroes for the network number, refers to the local network

– If 223.1.1.0/24 is the network and I am 223.1.1.52, locally

I can be reached using 0.0.0.52

• Address of all ones is the broadcast address for the local network

What is the dotted-decimal address?

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 25

• Address with the proper network number, and all ones for the host

number allows host to broadcast to a different network

– If 223.1.1.0/24 is a distant network, then 223.1.1.255

broadcasts to all hosts at the network

This and ping can can be used as a network attack, how?

• 127.x.y.z is reserved for loop-back testing

– Packet is never placed on the network, processed locally

Given a class A address, how many hosts can be connected tothe network?

E. W. Fulp Fall 2009

Page 14: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 26

IP Addresses and Routing

• We have introduced IP addresses and the concept of a network

– IP addresses are 32 bits long, and can be divided into classes

– Each class divides address into network and host portion

32 Bits

Range of hostaddresses

1.0.0.0 to127.255.255.255

128.0.0.0 to191.255.255.255

192.0.0.0 to223.255.255.255

224.0.0.0 to239.255.255.255

240.0.0.0 to247.255.255.255

Class

0 Network Host

10 Network Host

110 Network Host

1110 Multicast address

11110 Reserved for future use

A

B

C

D

E

– All hosts in one network have the same network portion,

different host portion; therefore, the addresses are hierarchical

Why is it important to identify the class of an address?

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 27

Routing Tables

How does a source host send a datagram to a destination host?

• The IP layer maintains a routing table in memory

– Remember, routing tables are next hop oriented

– Multiple hop paths are not recorded

• Each entry in the routing table has the following informationa

1. Destination address, either host or network address

2. IP address of the next-hop router

3. Flags specifying if next hop is host or network

4. Identification of the interface the datagram should be passed

to (e.g. multiple Ethernet cards attached)

aAbbreviated list of items, more later.

E. W. Fulp Fall 2009

Page 15: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 28

Example Routing Tables

223.1.3.27

223.1.3.2

223.1.2.9

223.1.3.1

223.1.2.1

223.1.2.2

223.1.1.4

223.1.1.1 223.1.1.2 223.1.1.3

A B

E

eth0

eth0

eth2 eth1

eth0

eth0

eth0

eth0 eth0 eth0

• In the diagram, each interface (Ethernet card) is labeled (in red)

• For example, the router has 3 interfaces (eth0, eth1, and eth2)

– Each interface must be uniquely identified, since it attaches a

unique network

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 29

• An abbreviated routing table for host A would be

Routing Table for A

Destination Next Hop Interface

223.1.1.0/24 eth0

223.1.2.0/24 223.1.1.4 eth0

223.1.3.0/24 223.1.1.4 eth0

– First entry indicates 223.1.1.0/24 is the local network

– The second and third entries indicate datagrams for

destinations on network 223.1.2.0/24 or 223.1.3.0/24

must be sent to 223.1.1.4

– eth0 is the Ethernet interface (only one card on A)

Each network is represented with one entry, how many wouldbe required if each host had a separate entry?

E. W. Fulp Fall 2009

Page 16: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 30

• An abbreviated routing table for the router would be

Routing Table for Router

Destination Next Hop Interface

223.1.1.0/24 eth0

223.1.2.0/24 eth1

223.1.3.0/24 eth2

– First entry indicates 223.1.1.0/24 is local on eth0

– Second entry indicates 223.1.2.0/24 is local on eth1

– Third entry indicates 223.1.3.0/24 is local on eth2

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 31

IP Routing Steps

• IP routing performs the following actions

1. Search routing table for complete destination address, if found

send packet to the next-hop entry

2. Search routing table for an entry that matches the destination

network number, if found send packet to the next-hop entry

– Must take into account possible subnet mask

3. Search for default entry, if found send to next-hop router

• IP search order is, host address → host network → default

• If all the steps fail, then the datagram is not deliverable

E. W. Fulp Fall 2009

Page 17: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 32

Routing Example: A → B

Assume A (223.1.1.1) sends datagram to B (223.1.1.3)

LinkHeader

IPHeader

Data

Dest: 223.1.1.3

LLA of: 223.1.1.3

223.1.1.1 223.1.1.3

• There is no host entry for 223.1.1.3

• There is a network entry for 223.1.1.0/24

• A link layer frame (containing the datagram) is created and

addressed to the link layer address of 223.1.1.3

We are at layer 3, how do we get a layer 2 address?

• Ethernet frame is sent and received by host B

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 33

Routing Example: A → E

Assume A (223.1.1.1) sends datagram to E (223.1.2.2)

Routing Table for A

Destination Next Hop Interface

223.1.1.0/24 eth0

223.1.2.0/24 223.1.1.4 eth0

223.1.3.0/24 223.1.1.4 eth0

Routing Table for Router

Destination Next Hop Interface

223.1.1.0/24 eth0

223.1.2.0/24 eth1

223.1.3.0/24 eth2

• Host A finds entry for 223.1.2.0/24 network

– Requires sending packet to 223.1.1.4

• Host A creates and sends link-layer frame (containing datagram)

addressed to the link-layer address of 223.1.1.4

– Therefore, the next-hop entry is used for the link-layer address

– IP destination address remains unchanged

E. W. Fulp Fall 2009

Page 18: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 34

• Router 223.1.1.4 receives frame and removes datagram

– Destination address is 223.1.2.2

– Router is allowed to forward datagrams

• Router finds entry for 223.1.2.0/24 network

– This is directly connected via eth1

– Datagram will be forwarded

• Router creates and sends link-layer frame (containing datagram)

addressed to the link-layer address of 223.1.2.2 on eth1

• Frame received by host E, datagram removed and processed

• N.B. operation of host and router are equivalent, except routers

are allowed to forward datagrams

E. W. Fulp Fall 2009

Internet Protocols CSC 343·643 Network Layer and IP 35

223.1.3.27

223.1.3.2

223.1.2.9

223.1.3.1

223.1.2.1

223.1.2.2

223.1.1.4

223.1.1.1 223.1.1.2 223.1.1.3

A B

E

eth0

eth0

eth2 eth1

eth0

eth0

eth0

eth0 eth0 eth0

2

1 LinkHeader

IPHeader

Data

Dest: 223.1.2.2

LLA of: 223.1.1.4

1

2 LinkHeader

IPHeader

Data

Dest: 223.1.2.2

LLA of: 223.1.2.2

E. W. Fulp Fall 2009

Page 19: Network Layer and IP

Internet Protocols CSC 343·643 Network Layer and IP 36

Another Routing Example

Assume 140.1.1.1 sends a datagram to 152.24.25.5

LinkHeader

IPHeader

Data

Dest: 152.24.25.5

LLA of: 140.1.1.25

140.1.1.1

LinkHeader

IPHeader

Data

Dest: 152.24.25.5

LLA of: 140.2.2.18

IPHeader

Data

Dest: 152.24.25.5modem

modem

SLIP

Internet

140.1.1.25

140.2.2.7

140.2.2.18

140.1.0.0/16

140.2.0.0/16

E. W. Fulp Fall 2009