Anda di halaman 1dari 85

MET 1313 COMMUNICATION

AND COMPUTER NETWORK


CHAPTER 4: NETWORK LAYER
1

Internet Architecture
Physical networks interconnected by a router

Interconnection via another network

Internetworking Principle
Interconnection of Packet Switching networks
use the services that the PS networks provide
adapt packet lengths to supported lengths (fragmentation)

Best Effort delivery


no prevention of packet loss
independent treatment of packets (no flow concept in
normal IPv4)
sequence integrity not guaranteed

Routers use destination network, not host address


need only to know how to reach a network
no influence of source host on route (normal IPv4)

No knowledge of full path to destination necessary


send to next hop

Internet Protocols

global addresses

port numbers
protocol number
IP addresses

subnetwork addresses

Introduction of new
applications:

advertise port number


instant worldwide reach
ability
software distributed via
HTTP or FTP
4

IP The Internet Protocol


Is IP a protocol at all?
What is a protocol?
a convention of data formats
a convention of what data units signify
a convention of the interaction of state machines

IP is a protocol, even if there are no state machines


involved

Why not use a purely bridged


network?
Why do we need IP or the Network Layer for?
Consider a pure bridged network
each end system has its Link Layer address built in
each bridge knows all end systems
broadcasts reach all nodes

Hierarchy needed to reduce effort


in computing routes / spanning tree
in storing end system addresses

Divide the worldwide network into several smaller


bridged networks

Router Network
End systems
have a network (IP) address assigned to each network interface
have neighbour router(s) configured (default route, configured
routes)
communicate within local network using Link Layer addresses

Routers (Intermediate Systems)


either: have a next hop entry for all IP networks (not: nodes!)
or (like above): know all IP networks on one side and have a default
router configured on the other
static routes configured (configuration / network management task)
dynamic routes are discovered using routing protocols
(communication with neighbour routers)
for each packet received: look up next hop and forward packet to
next hop using the appropriate Link Layer method

IP Protocol Functions
Connectionless, unreliable best-effort delivery of data
Datagram addressing and forwarding
IP header check
Segmentation and reassembly (fragmentation)
Error reporting (ICMP)

IP Packets
IP packet also called

datagram

IP packet header transmitted before user data

maximum total length: 65535 bytes


minimum total length: 20 bytes
(minimum header and no payload)

IP Packet Header Format


Bit positions:

HLE
N

10

IP Packet Header Field


Version (4 bits)
Currently it is Version 4

HLEN, Header Length (4 bits)


counts the number of 32bit words in the header
points to first data word
minimum = 5 (20 byte header)

11

IP Packet Header Field (2)


Type of Service (8 bits)

Influence on queuing
may have influence on routing decision
can be coupled to lower layer service classes
policy framework needed for general use
12

IP Packet Header Field (3)

length of the datagram (in octets), including IP header and data


at most 65535 octets
all hosts must be able to accept a datagram of 576 octets (512+64)
only send datagrams longer than 576 octets if the receiver can
handle them

identification of transmitted datagram


unique for transmitter (for the next 65535 packets)
used by receiver to reassemble fragmented datagrams

Bit 0: must be zero (MBZ)


Bit 1: DF 1 = dont fragment 0 = may fragment
Bit 2: MF 1 = more fragments 0 = last fragment

counts 8 octet (64 bits) words


indicates where the current fragment belongs in the datagram

13

IP Packet Header Field (4)

indicates the maximum residual time the datagram is allowed to


remain in the network
RFC791: measured in seconds, but:
each router must decrement the TTL value by 1
-> effectively implemented as

residual hop

count
necessary to avoid infinitely circling packets in the case of a
routing loop
(special problem of connectionless packet switching!)

indicates the next layer protocol (usually transport layer)


14

IP Packet Header Options


Usage is optional
Implementation is mandatory
Option Length
number of octets in (option-type + option-length + optiondata)
Option Type

Copy Flag (CF): 1 = copy / 0 = do not copy


(controls treatment of options under fragmentation)
Option Class (OC):
0 = control
2 = debugging & measurement
1,3 = reserved for future use

15

Differentiated Service Field


Redefinition of the Type of Service (TOS) field in the IP
header

6-bit code points (DSCP) instead of Precedence, D, T and


R fields
no guarantee of service
Local policy
hint on how to handle packets
dependent on hardware / local network capabilities

16

IP Address
IP address is use as an identifier in the IP layer of the TCP/
IP suite to identify devices/host connected in the network.
An IP address is a 32-bit address that is unique and
universal.
Address space: the total number of address used by the
protocol.
A protocol use N bits to define an address, the address
space is 2N because each bit can have two different
values; 0 or 1 and N bits can have 2N values.
IPv4 uses 32-bit addresses, which mean that address
space is
17

IP Address Parts
32 bit IP address is divided into Network ID and Host ID

first part of the IP address


used for routing packets towards a network
must be known by every Internet router
routers ignore the host ID part of the address when looking up
the next hop
routing is the same for all hosts with the same network ID

identifies a host within an IP network


all hosts on the same network have the same network ID
communication within one network uses lower layer
mechanisms to deliver packets
E.g. Ethernet and ARP
18

IP Addresses
32bit IP address specifies

a network (Network ID)


a host on this network (Host ID)

Optimized for fast extraction of Network ID part


Hosts attached to multiple networks (e.g. routers) must
have separate IP addresses at each interface
Network address
all Host ID bits = 0

Zero means

this

One means

all

network 0.0.0.0 = this network


useful during initialization phases when actual Network ID is
not known yet
broadcast addresses

19

Operation of TCP/IP

20

IPv4 Classful Address Formats

21

Notation
Binary
Three
common
notation of
IP address

Dotted
Decimal

Hexadeci
mal
22

Binary Notation
In binary notation, the IP address is displayed as 32 bits.
One or more spaces are usually inserted between each
octet (8 bits).
Each octet is often referred to as a byte.

01110100 01010001 00001010


11101010

23

Dotted Decimal Notation


To make IP address more compact and easier to read.
Internet addresses are usually written in decimal form with
a decimal point (dot) separating the bytes.
Because each byte (octet) is only 8 bits, each number in
the dotted-decimal notation is between 0 and 255.

10000000

00001011

00000011

00011111

128 . 11 . 3 . 31
24

Hexadecimal Notation
Sometimes an IP address can be seen in hexadecimal
notation.
Each hexadecimal digit is equivalent to four bits. This
means that a 32-bit address has 8 hexadecimal digits.
Hexadecimal notation normally has no added spaces or
dots; however, 0X (or 0x) is added at the beginning or the
subscript 16 at the end to show that the number is in
hexadecimal.
100000001 00001011 00001011

11101111

0X 81 0B 0B EF
becomes

0X810B0BEF or 810B0BEF16

25

Example
Change the following IP address from binary notation to
dotted-decimal notation

10000001 00001011 00001011 11101111


129
. 11
.
11
. 239
11000001 10000011 00011011 11111111
193
. 131
.
27
. 255
11100111 11011011 10001011 01101111
231
. 219
. 139 . 111
11111001 10011011 11111011 00001111
249
. 155
. 251
. 15
26

Example
Change the following IP addresses from dotted-decimal
notation to binary notation

111. 56.45.78
01101111 00111000 00101101 01001110
221.34.7.82
11011101 00100010 00000111 01010010
241.8.56.12
11110001 00001000 00111000 00001100
75.45.34.78
01001011 00101101 00100010 01001110
27

IP Addresses - Class A
Start with binary 0
All 0 reserved
01111111 (127) reserved for loopback
Range 1.x.x.x to 126.x.x.x
All allocated

28

IP Addresses - Class B
Start with binary 10
Range 128.x.x.x to 191.x.x.x
Second octet also included in network address
214 = 16,384 class B addresses
All allocated

29

IP Addresses - Class C
Start with binary 110
Range 192.x.x.x to 223.x.x.x
Second and third octet also part of network address
221 = 2,097,152 addresses
Nearly all allocated
see IPv6

30

Class in IP addressing
First
byte

Second
byte

Third
byte

Fourth
byte

First
byte

Class A

Class A

0-127

Class B

10

Class B

128 -191

Class C

110

Class C

192
-223

Class D

1110

Class D

224
-239

Class E

1111

Class E

240
-255

a. Binary notation

Second
byte

Third
byte

Fourth
byte

b. Dotted decimal notation

31

Example
Find the class of each address
227.12.14.87
(between 224 239) Class D
193.14.56.22
(between 192 223) Class C
14.23.120.8
(between 0- 127) Class A
252.5.15.111
(between 240-255) Class E
134.11.78.56
(between 128- 191) Class B
32

Netid and Hostid


In classful addressing, an IP address in class A, B or C is
divided into netid and host id.
These parts are of varying lengths, depending on the class
of the address.
Classes D and E are not divided into netid and hosted
because class D is use for multicast and class E is reserved
for future use.

33

Netid and Hostid


First
byte
Class A
Class B

Second
byte

Netid

Third
byte

Fourth
byte

Hostid
Netid

Hostid

Class C

Netid

Class D

Multicast address

Class E

Reserved for future

Hostid

34

Classless IP address
Classful addressing, which is almost obsolete, is replaced
with classless addressing.
Addressing are in variable length blocks which assigned to
no class.
Example: block of 2 addresses, 4 addresses, 128 addresses
and so on.
Here, the entire address space (232 addresses) is divided
into blocks of different sizes

35

Classless IP address
Only one restriction on the number of addresses in a block;
it must be a power of two (2,4,8,16).
Household :a block of 2 (21) addresses.
A small business: a block of 16 (24) addresses.
A large organization : a block of 1024 (210) addresses.

36

Classless IP address
The first addresses must be evenly divisible by the number
of addresses.
if a block contains 4 addresses, the first address must be divisible
by 4.
If the block contains 16 addresses, the first addresses must be
divisible by 16.
If the block has 256 addresses or less, check only the right most
byte.

However, if it has 65636 addresses or less, check only the


two right most byte and so on.
An address in classless addressing architecture is usually
given as shown below

37

Prefix and Prefix length


Prefix similar to
Prefix length the length of the prefix
- n in the CIDR notation

38

Relationship Between Mask and


Prefix Length
/n

Mask

/n

Mask

/1

128.0.0.0

/9

255.128.0.0

/2

192.0.0.0

/10

/3

224.0.0.0

/4

/n

Mask

/n

Mask

/17

255.255.128.0

/25

255.255.255.128

255.192.0.0

/18

255.255.192.0

/26

255.255.255.192

/11

255.244.0.0

/19

255.255.224.0

/27

255.255.255.224

240.0.0.0

/12

255.240.0.0

/20

255.255.240.0

/28

255.255.255.240

/5

248.0.0.0

/13

255.248.0.0

/21

255.255.248.0

/29

255.255.255.248

/6

252.0.0.0

/14

255.252.0.0

/22

255.255.252.0

/30

255.255.255.252

/7

254.0.0.0

/15

255.254.0.0

/23

255.255.254.0

/31

255.255.255.254

/8

255.0.0.0

/16

255.255.0.0

/24

255.255.255.0

/32

255.255.255.255

39

Suffix and Suffix length


Suffix similar to
Suffix length the length of the suffix
in CIDR notation
- 32 - n

40

Finding Subnet Mask


In classless addressing, the size of block is
It varies according to needs of the organization.
When the classless IP address is given, the block can be
found

41

Example1
Given IP address 167.199.170.82/27.
Find:
1) The first address in the block
2) The number of address in the block
3) The last address in the block.

42

First Address in the Block


The prefix length is 27, which means that we must keep the
first 27 bits as it is and change the remaining bits (5) to 0s.
Address in binary:

10100111 11000111 10101010 01010010

Keep the left 27 bits:

10100111 11000111 10101010 01000000

Result in CIDR notation:

167.199.170.64/27

Finding the number of address in the block is very simple.


The total number of addresses in the block is 232-n.

43

Number of Address
Finding the number of of address in
the block is very simple.
The total number of addresses in the
block is

232-n = 232-27= 25 = 32

44

Last Address
F i n d t h e c o m p l e m e n t o f m a s k f o r I P a d d re s s
167.199.170.82/27.
The mask is 255.255.255.224 , 11111111
11111111
11111111 11100000.
The complement is 00000000
00000000
00000000
00011111. Add the first address to the mask complement

167.199.170.64
0 . 0 . 0 .31
_____________
167.199.170.95
45

Example 2
Given IP address 190.87.140.202/29
Find:
1) The first address in the block
2) The number of address in the block
3) The last address in the block

46

Finding Subnet Address- Fixed


Length Subnets
The organization is granted the block 130.34.12.64/26. The
organization needs 4 subnets. What is the prefix length?

Solution:
We need 4 subnets, we need to add 2 more 1s because
log24=2 to the site prefix. The subnet prefix is then /28

47

The Site and The Subnet


130.34.12.64/26

1st subnet
/28
2nd
subnet

4th
subnet
/28

/28
3rd
subnet
/28

48

Finding Subnet Address


To find the range of address in each subnet
Site has 232-26=26=64 address
Each subnet has 232-28=24=16 address

1st address in the 1st subnet is 130.34.12.64/28


Last address of the 1st subnet is found by adding 15 (16-1)
to the first address
So the last address is 130.34.12.79/28

49

Exercise
The organization is granted the block 130.34.12.64/26. The
organization needs 8 subnets.
a) What is the prefix length?
b) How many address does each subnet can support?
c) Find the 1st and last add of the 1st subnet?

50

Variable Length Subnets


An organization is granted a block of addresses with the
beginning address 14.24.74.0/24. The organization needs to
have 5 subnets as shown below:
3 subnets ,each with 64 address
2 subnets ,each with 32 address
a) Determine the number of address for the sites.
b) Find the prefix for each subnet.
c) For each subnet, determine the first and last addresses
51

Variable Length Subnets


An organization is granted a block of addresses with the
beginning address 14.240.4.0/24. The organization needs
to have 11 subnets as shown below:
2 subnets ,each with 64 address
2 subnets ,each with 32 address
3 subnets, each with 16 address
4 subnets, each with 4 address
Determine the number of address for whole the site.
Find the prefix for each subnet.
52

Internet Control Message Protocol


(ICMP)
Companion protocol to IP

required in every IP implementation (part of IP)


uses IP datagrams for transport
protocol number 1

Used to report problems with IP datagram delivery


Error reporting only

message goes back to datagrams source IP address


application in end system can make use of the notification
no error correction

No error reports generated for ICMP packets

avoid network congestion due to error message avalanches

53

ICMP Messages
ICMP message format starts with a 64-bit header consisting
the following:
Type (8bits) field defines the type of ICMP message.
Code (8 bits) field specifies the reason for the particular
message type.
Checksum (16 bits) Checksum for the entire ICMP message.
This is the same checksum algorithm used in IP.
Parameters (32 bits) used to specify more lengthy parameters.

54

ICMP Messages
ICMP
Messages

Error reporting

Query

Report problems that a router or host may encounter when it


processes an IP packet

Usually occurs in pairs, help a host or a network manager


getting specific information from a router or another host
55

ICMP Messages - Category

56

Reachability Test
Uses ICMP echo request and echo reply

receiver of echo request returns echo reply message


optional data copied from echo request

Corresponding tool:

ping

transmit ICMP echo request

Wait for corresponding echo reply with matching identifier


and sequence number

57

Unreachable Destinations
Router cannot forward packet
destination host cannot accept packet

58

Route Change
Router are assumed to know a correct route to the
destination
Hosts have minimal routing information
can be started up knowing only one router
may learn additional information from routers

59

Subnet Mask
Used to request the local address mask from a router
broadcast if no router is known

Router replies to the request

60

Router Advertisement
Sent periodically by routers
soft state, i.e. state is only
kept for a given lifetime

Num Addrs = number of


entries in data part
Addr Size = size of address
entries in 32 bit words (IPv4:
1; IPv6: 4)
Lifetime = life time in
seconds for this
advertisement
default: 30 min (1800s),
periodic transmission every
10 min (600s)

61

Router Solicitation
Ask available routers to send an advertisement
immediately
Used by freshly booted hosts
Send to broadcast address (255.255.255.255)
Or to the all routers multicast address (224.0.0.2)

62

ARP(Address Resolution Protocol)


Link Layer (local / hardware) addresses are used in all
local communications
e.g. MAC addresses in Ethernet LAN

Source host wants to send a packet to destination


only receivers IP address is known

mechanism needed to find out hardware address


ARP used to discover local (hardware) address for a
given IP address on the local network

63

ARP Solution Example


A wants to transmit a datagram to
host with IP address IPB

Example local
network

A transmits an ARP broadcast to all


hosts on local network, including its
own IP and hardware addresses
B updates its ARP cache with A s
data
B sends reply back to A using As
hardware address
A updates its ARP cache with Bs data
64

ARP Solution Example

65

ARP Packets Example for Ethernet


and IP
Local network packets, not belonging to the IP layer

66

Encapsulation of the ARP packet in


the Ethernet frame

67

Example of ARP Request and reply


A host with IP address 130.23.43.20 and physical address
B2:34:55:10:22:10 has a packet to send to another host with
IP address 130.23.43.25 and physical address
A4:6E:F4::59::83:AB (which is unknown to the first host).
The two hosts are on the same Ethernet network.
Show the ARP request and reply packets encapsulated in
Ethernet frames.

68

Example of ARP Request and Reply


Bs IP add
As IP add
As Mac add

Unknown B MAC add

Bs MAC add
Bs IP add
As MAC add
As IP add

69

Reverse Address Resolution Protocol


(RARP)
Reverse Address Resolution Protocol
Used at host startup
e.g. for diskless hosts

requires RARP server(s)


determine host IP from hardware address
Request sent to broadcast hardware address
Reply sent to senders hardware address rather than
Target HA
RARP Ethertype = 803516
ARP Ethertype = 080616

70

RARP Example
A is booted

Example local
network

A transmits a RARP broadcast to


all hosts on local network
RARP servers C and E
recognize HAA and send a reply
to A including IPA

71

Routing Principle
How to deliver a datagram?
To a destination on the local network:
send the datagram directly
use e.g. ARP to obtain corresponding hardware address

To other destinations:
send the datagram via routers
Example:

Host A directly
connected to B, C,
D, E, F, G, R1, R2
to network N1
o route via R1
to network N2
o route via R2
72

Routing Algorithm
Extract destination IP address IPD from datagram and
compute network prefix N
If N matches any directly connected network address
deliver datagram to destination IPD over that network

(resolve IP to a physical address, encapsulate datagram, send frame)


D

else if the table contains a host-specific route for IPD


send datagram to next hop specified in routing table

else if the table contains a route for network N

send datagram to next hop specified in routing table

else if the table contains a default route

send datagram to the default router specified in the routing


table

else

report a routing error


73

Forwarding a Datagram
Get next hop from routing table
Get hardware address for next hop (ARP / ARP cache)
Reduce Time To Live (usually by 1)
Recompute header checksum
Send datagram on local network to the next hops
hardware address
address fields in IP header are not modified! (exception:
source routing option fields)

74

Hosts and Routers


Router
receives datagrams on all
physical networks
looks up in routing table to
forward datagrams to their
next hops or
forward datagrams to their
destination
should know about all locally
available routers
talks to other routers (routing
protocol)
(and can be addressed itself)

Host
receives datagrams
sends out datagrams
according to routing table
to destination if local
to next hop router if non-local
can live with knowing just one
router
multi-homed host can have
multiple network addresses
Be careful when forwarding
packets (avoid routing loops)

75

Subnet Routing
Include subnet mask in routing table
Check if 32bit AND of destination address and network
mask in routing table entry is equal to network address in
routing table entry
Next hop still needs to be accessible on the local network
Beware of ambiguities!
Use consistent subnet masks across all networks within the
same subnetted IP network
Otherwise subnet broadcasting is ambiguous

Use contiguous bits to form subnet masks


Hosts can obtain local subnet masks from router via ICMP

76

Routing Algorithms
For a given topology, find out the shortest path to each
destination.
Challenges
avoid loops
react to failures
react to topology changes
discover topology

Can be grouped in two


Non-adaptive static
Adaptive dynamic

77

Routing Algorithms
Routing protocols

Intra domain

Inter domain

Distance vector
(i.e.RIP)

Path Vector (i.e.


BGP)

Link state aka


OSPF (i.e.Djikstra)

78

Routing Algorithms

Shortest Path
routing
Non adaptive
(static)
Flooding

Adaptive
(dynamic)

Distance vector
routing
(Bellman-ford)
Link state
Routing

79

Shortest Path Routing


Simple and easy to understand
To choose a route between a given pair of routers, the
algorithm will find the shortest path between them on the
graph
Measure path length can use several metric such as
number of hops or physical distances.

80

Djikstra's Algorithm
Djikstra's algorithm solves the problem of finding the
shortest path from a point in a graph (the source) to a
destination.
One can find the shortest paths from a given source to all
points in a graph in the same time
This problem is sometimes called the single-source shortest
paths problem.

81

Graph Algorithm- Routing Table

82

Routing Protocols
Routing protocols used to
discover routes
propagate route information
validate routes
check route consistency

Autonomous System (AS)


group of networks and routers controlled by a single
administrative authority
hidden networks advertised to other AS
central assignment of AS numbers

Each AS can choose a different routing protocol

83

AS Communications
Communication between different Autonomous Systems
exterior gateway protocols (EGP)
propagation of reachability information
routing metrics are not communicated or interpreted
internal structures are hidden

Communication within Autonomous Systems


interior gateway protocols (IGP)
propagation of reachability information
propagation of routing metrics (distance, cost, etc)
optimisation possible using internal structure information

84

Protocol Overview
Exterior Gateway Protocols
Border Gateway Protocol (BGP), currently BGP-4

Interior Gateway Protocols


OSPF (Open Shortest Path First)
IGRP (Interior Gateway Routing protocol)
RIP (Routing Information Protocol)

85

Anda mungkin juga menyukai