F-6.1-IP.2009

dingdongboomNetworking and Communications

Oct 27, 2013 (3 years and 9 months ago)

69 views

Network
-
Layer
:



IPv4

(Internet Protocol)


RFC 791

Key Functions of the Network Layer



Global Addressing

9

Routing

9

Fragmentation and
reassembly


IP in TCP/IP Stack

Media Access Control

(Ethernet, Token Ring, FDDI, X.25, PPP, etc.)

User Datagram Protocol

(UDP)

RFC 768

~ connectionless transport ~

Transmission Control Protocol

(UDP)

RFC 793

~ connection
-
oriented transport ~

Upper
-
Layer Protocols

~ such as SNMP, telnet, FTP, HTTP, POP3, etc. ~

Upper

Transport

Network

Data Link

ARP

Internet Control

Messaging Protocol


(ICMP)

RFC 792

Internet Protocol version 4 (IPv4)

RFC 791

RARP


Unique addressing allows communication

between end stations


Path choice is based on location


Location is represented by an address

UNIX Host

UNIX Host

Company A

Company B

Introduction to TCP/IP Addresses

Internet

IP Addresses

• IP addresses are
logical

addresses (
not

p
hysical
)

• Every host must have a
unique

IP

address.



IP addresses are assigned by a central

authority
(
Internet Corporation for Assigned

Names and
Numbers
--

ICANN)



32 bits




Decimal
:


195. 19 . 40 . 56


Binary
:


11000011 . 00010011 . 00011110 . 00101000


HEX
:



C
3 . 13 . 1Е . 28



Includes a
network ID

and a
host ID
.

IP Address Classes

1


126


Range of


first octet:


128
-
191


192
-
223


224
-
239


240
-
247


Special

adresses


network address


(
адрес сети)



limited broadcast



(
пакет с таким адресом назначения должен рассылаться всем
узлам, находящимся в той же сети, что и источник этого
пакета
)



broadcast


(
пакет, имеющий такой адрес рассылается всем узлам сети с
заданным номером
)



Loopback interface:




127.0.0.0


127.255.255.255


1 1 1 1 .............................. 1

Network



1 1 1 ................ 1

Network


0 0 0 ................ 0

Broadcast Addresses

172.16.1.0

172.16.2.0

172.16.3.0

172.16.4.0

172.16.3.255

(Directed broadcast)

255.255.255.255

(Local network broadcast)

X

Private networks

A: 10.0.0.0
-

10.255.255.255

B: 172.16.0.0


172.31.255.255

C: 192.168.0.0


192.168.255.255


Reserved for automatic private addressing (DHCP):

169.254.0.0


169.254.255.255


NAT: Network Address Translation


Motivation:

local network uses just one IP address as far as
outside word is concerned:


no need to be allocated range of addresses from ISP:
-

just one
IP address is used for all devices


can change addresses of devices in local network without
notifying outside world


can change ISP without changing addresses of devices in local
network


devices inside local net not explicitly addressable, visible by
outside world (a security plus).


NAT: Network Address Translation

10.0.0.1

10.0.0.2

10.0.0.3

S: 10.0.0.1, 3345

D: 128.119.40.186, 80

1

10.0.0.4

138.76.29.7

1:

host 10.0.0.1

sends datagram to

128.119.40, 80

NAT translation table

WAN side addr LAN side addr

138.76.29.7, 5001 10.0.0.1, 3345

…… ……

S: 128.119.40.186, 80

D: 10.0.0.1, 3345


4

S: 138.76.29.7, 5001

D: 128.119.40.186, 80

2

2:

NAT router

changes datagram

source addr from

10.0.0.1, 3345 to

138.76.29.7, 5001,

updates table

S: 128.119.40.186, 80

D: 138.76.29.7, 5001


3

3:

Reply arrives


dest. address:


138.76.29.7, 5001

4:

NAT router

changes datagram

dest addr from

138.76.29.7, 5001 to 10.0.0.1, 3345



NAT: Network Address Translation

Implementation:

NAT router must:



outgoing datagrams:

replace

(source IP address, port #) of
every outgoing datagram to (NAT IP address, new port #)

. . . remote clients/servers will respond using (NAT IP
address, new port #) as destination addr.



remember (in NAT translation table)

every (source IP address,
port #) to (NAT IP address, new port #) translation pair

address, port #) stored in NAT table



incoming datagrams:

replace

(NAT IP address, new port #) in
dest fields of every incoming datagram with corresponding
(source IP address, port #)

IP Addressing: Solutions


Subnetting


Variable Length Subnet Mask (VLSM)




Supernetting


Classless InterDomain Routing (CIDR)

Network prefix and extended network prefix

Subnetting


Граница подсети может приходиться на любой из 32 бит
в
IP

адресе


Задается
маской
подсети



140 . 192 . 9 . 63 /25

10001100 11000000 00001001 00111111




network + subnet host



140 . 192 . 9 . 0
This network

10001100 11000000 00001001 00000000



140 . 192 . 9 . 127
Directed broadcast

10001100 11000000 00001001 00000000



255 . 255 . 255 . 128
Netmask

11111111 11111111 11111111 10000000



Network 172.16.0.0

172.16.0.0

Addressing without Subnets


Network 172.16.0.0

Addressing with Subnets

172.16.1.0

/24

172.16.2.0

/24

172.16.3.0

/24

172.16.4.0

/24

Decimal Equivalents of Bit Patterns

1

0

0

0

0

0

0

0

=

128

1

1

0

0

0

0

0

0

=

192

1

1

1

0

0

0

0

0

=

224

1

1

1

1

0

0

0

0

=

240

1

1

1

1

1

0

0

0

=

248

1

1

1

1

1

1

0

0

=

252

1

1

1

1

1

1

1

0

=

254

1

1

1

1

1

1

1

1

=

255

128

64

32

16

8

4

2

1

IP addressing: CIDR


Classfull addressing:


inefficient use of address space


e.g., class B net allocated enough addresses for 65K hosts,
even if only 2K hosts in that network



CIDR:

C
lassless
I
nter
D
omain
R
outing


network portion of address of arbitrary length


address format:
a.b.c.d/x
, where x is # bits in network portion of
address

11001000 00010111

0001000
0 00000000

network

part

host

part

200.23.16.0/23

Hierarchical addressing: route aggregation

“Send me anything

with addresses

beginning

200.23.16.0/20”

200.23.16.0/23

200.23.18.0/23

200.23.30.0/23

Fly
-
By
-
Night
-
ISP

Organization 0

Organization 7

Internet

Organization 1

ISPs
-
R
-
Us

“Send me anything

with addresses

beginning

199.31.0.0/16”

200.23.20.0/23

Organization 2

.

.

.

.

.

.

Hierarchical addressing allows efficient advertisement of routing

information:

ISPs
-
R
-
Us has a more specific route to Organization 1

CIDR


Classless Inter
-
domain Routing


Employ supernetting information in IP
routers


Advertise smaller CIDR blocks


Decreases the routing table size

IP
Datagrams

IP
packet structure

16
-
bit total packet length

16
-
bit identification

TOS

4
-
bit
ver

4
-
bit
IHL

13
-
bit Fr offset

flags

3
-
bit

DATA

Header checksum

TTL

Protocol

Source address

Destination address

Options (+padding)

Version.Current protocol version is 4.

IHL
-

IP header length
. IHL is quantity
of 32
-
bit words in IP header. This field has
4
-
bit length => maximum header length is
60 bytes

15

16

31

0

TOS
-

type of service

contain of a 3
-
bit
precedence bits (ignored), 4 TOS bits, and
unused bit which must be 0.
4 TOS bits:


minimize delay


maxm,ize throughput


maximize reliability


minimize monetary cost

Only 1 of these 4 bits can be turned on

TPL
-

total packet length

is total IP
packet’s length in bytes

(
IP Header +
DATA). Then maximum length of IP
packet is 65535 bytes.

IDENTIFICATION

-

this field is used
when IP need fragment fatagrams.
Identification identifies each datagram and
is incremented each time a datagram is
sent We’ll see meaning of this field when
we talk about fragmentation

FLAGS and FRAGMENT OFFEST

see also when we talk about fragmentation

IP
packet structure

DATA

16
-
bit total packet length

16
-
bit identification

TOS

4
-
bit
ver

4
-
bit
IHL

13
-
bit Fr offset

flags

3
-
bit

Header checksum

TTL

Protocol

Source address

Destination address

Options (+padding)

TTL
-

time
-
to
-
live

sets an upper limit of
routers through which a datagram can pass.
This field is decremented each time when
datagram pass the router. When this field
became
0

a datagram is dropped by router
and ICMP message is sent to datagram’s
sender.

15

16

31

0

PROTOCOL

-

this field identifies DATA
portion of datagram (which protocol is
encapsulated into IP datagram).

HEADER CHECKSUM

is calculated for
IP header only.

SOURCE and DESTINATION
addresses

is sender’s and receiver’s IP
addresses.

OPTIONS
is a variable
-
length field which
contain some options. We’ll discuss some
of them later. The option field always end
on a 32
-
bit boundary. PAD bytes (value is
0) are added if necessary.

DATA

is data.

Options

(
Variable length
)

type

:

f
c



Flag copy indicates whether (1) or not (0) the option

field is to be copied

when the datagram is

fragmented.

c
lass

0
control


1
reserved


2
debugging and measurement


length

Counts the length (in bytes) of the option, including the type and length

fields.

option data

Contains data relevant to the option.

0
End of option list.
(class0)

1
No operation.
(class0)

3
Loose source routing.
(class0)

4
Internet time stamp

(class2)

7
Record route.
(class0)

9
Strict source routing.
(class0)

option number

Options
, detail

Record route
(number 7, class0)

Strict source routing
(number 9,class0)

Loose source routing
(number 3, class0)

Internet time stamp

(number 4,class2)

flag:

0

Time stamps only, stored in consecutive 32
-
bit
words.

Pointer+4

1

Each time stamp is preceded by the IP address
of the registering module.

Pointer+ 8

2

The IP address fields are pre
-
specified, and an
IP module only registers

when it finds its own
address in the list.


t
ime stamp
:
A 32
-
bit time stamp recorded
in milliseconds since midnight UT (GMT)

Key Functions of the Network Layer



Global Addressing

9

Routing

9

Fragmentation and


reassembly


Network
-
Layer Protocol Operations


Each router provides its services to support

upper
-
layer functions

X

Y

A

B

C

Application

Presentation

Session

Transport

Network

Data Link

Physical

Application

Presentation

Session

Transport

Network

Data Link

Physical

A

B

C

X

Y

Network

Data Link

Physical

Network

Data Link

Physical

Network

Data Link

Physical

IP reframing

(forwarding)

Destination

MAC

Source

MAC

Type

0x0800

DATA

IP datagram

CRC


Packet:

Routing table (Examples)

UNIX:


Destination Gateway Genmask Flags Metric Iface

195.19.203.160 0.0.0.0 255.255.255.224 U 0 eth1

195.19.203.96 0.0.0.0 255.255.255.224 U 0 eth0

192.168.0.0 0.0.0.0 255.255.255.0 U 0 eth1

127.0.0.0 0.0.0.0 255.0.0.0 U 0 lo

0.0.0.0 195.19.203.97 0.0.0.0 UG 0 eth0


Win2000:



Network Destination Netmask Gateway Interface Metric


0.0.0.0 0.0.0.0 195.19.203.161 195.19.203.162 1


127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1


195.19.203.160 255.255.255.224 195.19.203.162 195.19.203.162 1


195.19.203.162 255.255.255.255 127.0.0.1 127.0.0.1 1


195.19.203.255 255.255.255.255 195.19.203.162 195.19.203.162 1


192.168.2.0 255.255.255.0 192.168.2.2 195.19.203.162 1


192.168.2.2 255.255.255.255 127.0.0.1 127.0.0.1 1


192.168.2.255 255.255.255.255 192.168.2.2 195.19.203.162 1


224.0.0.0 224.0.0.0 195.19.203.162 195.19.203.162



255.255.255.255 255.255.255.255 195.19.203.162 195.19.203.162 1


Routing Algorithm


Extract destination IP address,
D
, and compute the
network prefix,
N

1.
If N matches
direct network

connection

Then resolving D to a MAC address, encapsulating
the datagram, and send it

2.
Else if
host
-
specific route

found

Then send the datagram

3.
Else if entry exists for
network

N, send it

4.
Else if entry exists for
default route
, send it

5.
Else routing error

Making the “Route” Decision

131.21.0.0

131.34.0.0

131.22.0.0


Host match?


Network match?


Default gateway?

Destination


Gateway


Flags

Interface

127.0.0.1


127.0.0.1


UH


Int.

131.21.0.0


131.22.1.1


UG


A

131.36.0.0


131.34.2.4


UG


B

131.21.1.1


131.22.1.1


UG


A

Default


131.34.2.4


UG (0.0.0.0)


B

Host 1.1

Host 6.12

2.1

1.1

3.1

2.2

2.4

2.5

131.36.0.0

A

B

Router

Router

Router

Правила маршрутизации



Поиск совпадающего адреса хоста.


Поиск совпадающего адреса сети.


Поиск пункта по умолчанию
.

Ethernet and loopback device drivers

Functions of a router

Processing an IP datagram in an IP module

Routing table: sources


Initialization of interfaces in process of the booting.


127.0.0.0/8


Directly connected network


Default


Or re
-
configure of the interface


#ifconfig eth0 110.70.70.3 netmask 255.255.255.240 broadcast 110.70.70.15 up


Static routes


#route add

net 192.168.11.0 netmask 255.255.255.0 eth1


C:>route add 192.168.11.0 mask 255.255.255.0 192.168.11.2 metric 1 if 2


ICMP
-
redirects


Dynamic routes


on router only;


from routing daemon (routed, gated, zebra, etc);


routing protocols RIP,OSPF, etc

Gateway Redirect


ICMP: Internet Control Message Protocol


Dynamic host route entry added to sender’s route table

10.2.0.0/24

10.1.0.0/24

Router

#1

Ping 10.1.2.1

10.1.2.1

Router

#2

Internet

IP datagram 1

ICMP Redirect

route add
-
host 10.1.2.1 gateway 10.2.0.4

10.2.0.50

10.1.0.50

10.2.0.1

1

3

2

2

2

Rout
ed

versus Rout
ing

Protocol


Routed

protocol

used between

routers to direct

user traffic



Examples: IP, IPX




Routing

protocol

used only between

routers to maintain

tables



Examples: RIP,

OSPF, BGP

Network

Protocol

Destination

Network

Protocol
Name

1.0

2.0

3.0

Exit Port

to Use

1.1

2.1

3.1

Key Functions of the Network Layer



Global Addressing

9

Routing

9

Fragmentation and


reassembly


IP Fragmentation & Reassembly


В сети имеются сегменты с разным
типом среды передачи


=
>
разные
MTU (Max. Transfer Unit)



Большие
IP
дейтаграммы


делятся

(“fragmented”)

для передачи по
участкам сети с малым
MTU



Сборка
(
“reassembly”
)

производится только в пункте
конечного назначения



Поле
IP
-
заголовка

Identification


используется для идентификации
фрагментов, принадлежащих
исходной дейтаграмме

fragmentation:

in:

one large datagram

out:

3 smaller datagrams

reassembly


MTU

Ethernet
Hader

IP Header

TCP Header

DATA

Eternet

Trailer


MSS

IP
packet structure

16
-
bit total packet length

TOS

4
-
bit
ver

4
-
bit
IHL

DATA

Header checksum

TTL

Protocol

Source address

Destination address

Options (+padding)

15

16

31

0

16
-
bit identification

flags

3
-
bit

13
-
bit Fr offset

Fragmentation: IP Header

16
-
bit: Identification

3
-
bit: Flags

13
-
bit: Fragment offset

0

DF

MF

Identification
:

Уникальный номер для каждой дейтаграммы назначается отправителем. Все
фрагменты дейтаграммы будут иметь тот же номер идентификации.


Flags
:


0

Reserved


DF

Don't Fragment: 0


фрагментация разрешена,





1


фрагментация запрещена


MF

More Fragments: 0
-

последний фрагмент этой дейтаграммы,






1


не последний фрагмент.


Fragment Offset
:
Смещение фрагмента.

Устанавливается при фрагментации, используется при сборке.

Указывает на какой позиции в поле данных исходной дейтаграммы находится
фрагмент. Ед.измерения 64
bit =>
минимальный размер фрагмента = 8 байт

IP Fragmentation