1
Computer Networks
The Network Layer
Main Functions
3
Design Issues
• Services provided to transport layer. • How to design network-layer protocols.
Store-and-Forward Packet Switching
5
Services
• What kind of services provided to transport
layer?
• Connection-oriented versus connectionless
service?
Connectionless Service
• Datagram network.
• “Move all intelligence to the edges”.
– Routers just route.
– Everything else should be done end-to-end.
• No ordering, no flow/congestion control, no
reliable delivery.
• Best-effort service model.
7
Connection-Oriented Service
• Virtual circuit networks. • `A la telephone network. • Reliable, ordered service.
• Virtual connection established from source to
destination.
• E.g., X-25, ATM.
Datagram Network Operation
• How does it work?
• Data from transport layer is broken into
packets, or datagrams.
• Network layer at host adds network-layer
9
Datagram Network: Example
• Routing within a diagram subnet.
Virtual Circuit Network Operation
• Connection-establishment before sending
data.
– All traffic for that connection follows same
11
Virtual Circuit Network: Example
• Routing within a virtual-circuit subnet.
Virtual-Circuit versus Datagram Subnets
13
Routing
Routing
• One of the main functions of network layer. • Routing versus forwarding?
15
Routing Algorithm
• Computes routing tables. • Properties:
– Correctness. – Robustness. – Stability. – Optimality.
• Try to optimize a certain metric.
Optimality Principle
• General statement about optimal routes
(topology, routing algorithm independent).
• If router J is on optimal path between I
and K, then the optimal path from J to K
also falls along the same route.
– Proof by contradiction.
• Corollary:
17
Types of Routing Algorithms
• Non-adaptive versus adaptive.
Adaptive and Non-adaptive Routing
• Non-adaptive routing:
– Fixed routing, static routing.
– Do not take current state of the network (e.g.,
load, topology).
– Routes are computed in advance, off-line, and
downloaded to routers when booted.
• Adaptive routing:
– Routes change dynamically as function of current
state of network.
– Algorithms vary on how they get routing
19
Static Algorithms
(Non-Adaptive)
1.Shortest-path routing.
2.Flooding.
Shortest-Path Routing
• Problem: Given a graph, where nodes
represent routers and edges, links, find
shortest path between a given pair of nodes.
• What is shortest in shortest path?
– Depends on the routing metric in use.
– Example: number of hops (static), geographic
21
Dijkstra’s Shortest-Path Algorithm
• Initially, links are assigned costs.
• As the algorithm executes, nodes are labeled
with its distance to source along best known path.
• Initially, no routes known, so all nodes are
labeled with infinity.
• Labels change as the algorithm proceeds. • Labels can be temporary or permanent.
– Initially all labels are tentative.
– A label becomes permanent if it represents the
shortest path from the source to the node.
Shortest Path Routing
Find shortest-path from A to D:Start
Label each adjacent node with distance to
A.
23
Flooding
• Every incoming packet forwarded on every
outgoing link except the one it arrived on.
• Problem: duplicates. • Constraining the flood:
– Hop count.
– Keep track of packets that have been flooded.
• Robust, shortest delay (picks shortest path as
one of the paths).
Flooding: Example
25
Dynamic Routing Algorithms
•
(
Adaptive Routing)
– Distance vector routing.
– Link state routing.
Distance Vector Routing
• Aka, Bellman-Ford (1957), Ford-Fulkerson
(1962).
• Original ARPANET routing; also used by
Internet’s RIP.
• Each router keeps routing table (or routing
vector) with best known distance to each
destination and corresponding outgoing
interface.
27
Distance Vector (Cont’d)
• Routing table at each router:
– One entry per participating router.
– Each entry contains outgoing interface and distance to
corresponding destination.
– Metric: number of hops, delay, queue length. – Each router knows distance to its neighbors.
• Old ARPANET algorithm: DV where cost metric
is outgoing link queue length.
29
Routing Updates
•
Every T interval, routers exchange
routing updates.
•
Routing update from router X consists of
a vector with all destinations and the
corresponding distance from X to them.
•
When router Y receives an update from
X, it can estimate its distance to router Z
through X as D
yz= D
yx+ D
xz.
•
Router Y receives update from all its
neighbors and builds a new RT.
Distance Vector: Example
14
6
2 3
5
1 Node Distance Next 2 3 3 2 1 9 9 5 1 2 1 0 -2 -2 -2 3 5 3 4 1 4 5 6 3 6 8 3 T=T0 T=T1 3 7 5 2 3 4 0 4 2 3 0 2 2 2 0 3 1 1 5 3 3
Node Distance Next
31
Problems
1.Routing loops.
2.Slow convergence.
3.Counting to infinity.
Count-to-Infinity
• Good news propagate faster.
A B C D E
Initially, A down:
A comes up: infinity1
1 2 infinity infinity (after 2 exchanges) 1 2 3 infinity (after 3 exchanges) 1 2 3 4 (after 4 exchanges) infinity infinity infinity infinity infinity
33
Count-to-Infinity (Cont’d)
• But, bad news propagate slower!
A B C D E
Initially, all up:
A goes down: 1 2 3 43 2 3 4 (after 1 exchange) 3 4 3 4 (after 2 exchanges) 5 4 5 4 (after 3 exchanges) 5 6 5 6 (after 4 exchanges) 7 6 7 6 (after 5 exchanges) 7 8 7 8 (after 6 exchanges) …. infinity
Count-to-Infinity (Cont’d)
• Gradually routers work their way up to infinity.
• Number of exchanges depends on how large is
infinity.
35
Solution
•
Routing loops:
– Path vector: record actual path used in the DV. – Previous hop tracing: records preceding router.
•
Count-to-infinity:
– Split horizon: router reports to neighbor cost “infinity”
for destination if route to that destination is through that neighbor.
Split Horizon
• Tries to make bad news spread faster.
• A node reports infinity as distance to node
X on link packets to X are sent.
• Example, in the first exchange, C tells D
its distance to A but tells B its distance to
A is infinity.
– So B discovers its link to A is down and C’s
37
Link State Routing
• DV routing used in the ARPANET until 1979,
when it was replaced by link state routing.
• Used by the Internet’s OSPF.
• Based on Dijkstra’s “all pairs shortest path”
algorithm.
• Plus link state updates.
Link State Routing (Cont’d)
• Link state routing is based on:
– Discover your neighbors and measure the
communication cost to them.
39
Finding Neighbors
• When router is booted, its first task is to find
who its neighbors are.
• Special single-hop “hello” packets.
• Cost metric:
– Number of hops: in this case, always 1. – Delay: “echo” packets and measure RTT/2. – Load?
Generating Link State Updates
• Link state packets (LSP).
– Sender identity. – Sequence number. – TTL.
– List of (neighbor, cost).
• When to send updates?
– Proactive: periodic updates; how often?
– Reactive: whenever some significant event is detected,
e.g., link goes down.
41
Processing Updates
• When LSP is received:
– Check sequence number.
– If higher than current sequence number, keep it and
flood it; otherwise, discard it.
– Periodically decrement TTL.
• When TTL=0, purge LSP.
Computing Routes
• Routers have global view of network.
– They receive updates from all other routers with their
cost to their neighbors.
– Build network graph.
43
Measuring Line Cost
• A subnet in which the East and West parts
are connected by two lines.
Building Link State Packets
45
Distributing the Link State
Packets
B’s LSP buffer: each row corresponds to a recently LSP that hasn’t been processed yet.
Link State Routing: Problems
• Scalability:
– Storage: kn, where n is number of routers and
k is number of neighbors.
– Computation time.
47
DV versus LS
• DV:
– Node tells its neighbors what it knows about everybody. – Based on other’s knowledge, node chooses best route. – Distributed computation.
• LS:
– Node tells everyone what it knows about its neighbors. – Every node has global view.
– Compute their own routes.
Hierarchical Routing
•
For scalability:
– As network grows, so does RT size, routing update
generation, processing, and propagation overhead, and route computation time and resources.
•
Divide network into routing regions.
– Routers within region know how to route packets to
all destinations within region.
49
Hierarchical Routing: Example
1B 1A 1C 2A 2B 2C 2D 3A 3B 4A 4B 4C 5E 5D 5C 5B 5A
Dest. Next Hops
1A - -1B -1B 1 1C 1C 1 2A 1B 2 2B 1B 3 2C 1B 3 2D 1B 4 3A 1C 3 3B 1C 2 4A 1C 3 4B 1C 4 4C 1C 4 5A 1C 4 5B 1C 5 5C 1B 5 5D 1C 6 5E 1C 5 1A Flat routing:
Hierarchical Routing: Example
1B 1A 1C 2A 2B 2C 2D 3A 3B 4A 4B 4C 5E 5D 5C 5B 5A
Dest. Next Hops
51
Hierarchical Routing
• Optimal paths are not guaranteed.
– Example: 1A->5C should be via 2 and not 3.
• How many hierarchical levels?
– Example: 720 routers.
• 1 level: each router needs 720 RT entries.
• 2 levels: 24 regions of 30 routers: each router’s
RT has 30+23 entries.
• 3 levels: 8 clusters of 9 regions with 10 routers:
each router’s RT 10+8+7.
Many-to-Many Routing
• Support many-to-many communication.
• Example applications: multi-point data
53
Broadcasting
• Send to ALL destinations.
• Several possible routing mechanisms to broadcasting.
• Simplistic approach: send separate packet to
each destination.
– Simple but expensive.
– Source needs to know about all destinations.
• Flooding:
– May generate too many duplicates (depending on node connectivity).
Multidestination Routing
•
Packet contains list of destinations.
•
Router checks destinations and determines on
which interfaces it will forward packet.
– Router generates new copy of packet for each output
line and includes in packet only the appropriate set of destinations.
55
Spanning Tree Routing
• Use spanning tree (sink tree) rooted at
broadcast initiator.
• No need for destination list.
• Each on spanning tree forwards packets on all
lines on the spanning tree (except the one the packet arrived on).
• Efficient but needs to generate the spanning
tree and routers must have that information.
Reverse Path Forwarding
•
Routers don’t have to know spanning tree.
•
Router checks whether broadcast packet
arrived on interface used to send packets to
source of broadcast.
– If so, it’s likely that it followed best route and thus not
a duplicate; router forwards packet on all lines.
57
Broadcast Routing
Reverse path forwarding. (a) A subnet. (b) a Sink tree. (c)The tree built by reverse path forwarding.
Multicasting
• Special form of broadcasting:
– Instead of sending messages to all nodes, send
messages to a group of nodes.
• Multicast group management:
– Creating, deleting, joining, leaving group.
– Group management protocols communicate group
59
Multicast Routing
• Each router computes spanning tree covering all
other participating routers.
– Tree is pruned by removing that do not contain
any group members.
1,2 1 1,2 2 2 1 1 2 1,2 1 1,2 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2
Shared Tree Multicasting
• Source-rooted tree approaches don’t scale well!
– 1 tree per source, per group!
– Routers must keep state for m*n trees, where m is number
of sources in a group and n is number of groups.
• Core-based trees: single tree per group.
– Host unicast message to core, where message is
multicast along shared tree.
61
Internetworking
Internetworking
• What is it?
– Connecting networks together forming a single
63
Connecting Networks
• A collection of interconnected networks.
How Networks Differ
65
How Networks Can Be Connected
• (a) Two Ethernets connected by a switch.
• (b) Two Ethernets connected by routers.
How to Internet?
• Connection-oriented versus connectionless
internetworking.
• Connection oriented internetworking:
– Based on VC concatenation.
• Connectionless internetworking follows the
67
Concatenated Virtual Circuits
. Builds VC crossing the different networks.
. Use of gateways to perform necessary conversions. Gateway
Connectionless Internetworking
69
Translating versus “Gluing”
• Translation: converting between different
protocols.
• Hard!
• Alternative: “gluing”.
– I.e., using the same network layer protocol
everywhere.
– That’s what IP does!
Tunneling
• Interconnecting source and destination on
separate networks but of the same type.
S
71
Tunneling Analogy
73
Internetworking
Internetwork Routing
• Inherently hierarchical.
– Routing within each network: interior gateway
protocol (IGP).
– Routing between networks: exterior gateway
protocol (EGP).
• Within each network, different routing
algorithms can be used.
75
Internetwork Routing: Example
• (a) An internetwork. (b) A graph of the internetwork.
Internetwork Routing (Cont’d)
• Typically, packet starts in its LAN. Gateway
receives it (broadcast on LAN to “unknown”
destination).
• Gateway sends packet to gateway on the
77
Fragmentation
• Happens when internetworking.
• Network-specific maximum packet size.
– Width of TDM slot. – OS buffer limitations.
– Protocol (number of bits in packet length field).
• Maximum payloads range from 48 bytes (ATM
cells) to 64Kbytes (IP packets).
Problem
• What happens when large packet wants to
travel through network with smaller maximum packet size? Fragmentation.
• Gateways break packets into fragments; each
sent as separate packet.
• Gateway on the other side have to reassemble
fragments into original packet.
• 2 kinds of fragmentation: transparent and
79
Types of Fragmentation
• (a) Transparent fragmentation. (b)
Nontransparent fragmentation.
Transparent Fragmentation
• Small-packet network transparent to other
subsequent networks.
• Fragments of a packet addressed to the same
exit gateway, where packet is reassembled.
– OK for concatenated VC internetworking.
• Subsequent networks are not aware
fragmentation occurred.
• ATM networks (through special hardware)
81
Problems with Transparent
Fragmentation
• Exit gateway must know when it received all the
pieces.
– Fragment counter or “end of packet” bit.
• Some performance penalty but requiring all
fragments to go through same gateway.
• May have to repeatedly fragment and
reassemble through series of small-packet networks.
Non-Transparent
Fragmentation
• Only reassemble at destination host.
– Each fragment becomes a separate packet. – Thus routed independently.
• Problems:
– Hosts must reassemble.
– Every fragment must carry header until it reaches
83
Keeping Track of Fragments
• Fragments must be numbered so that original data stream can be reconstructed.
• Tree-structured numbering scheme:
– Packet 0 generates fragments 0.0, 0.1, 0.2, …
– If these fragments need to be fragmented later on, then 0.0.0, 0.0.1, …, 0.1.0, 0.1.1, …
– But, too much overhead in terms of number of fields needed.
– Also, if fragments are lost, retransmissions can take alternate routes and get fragmented differently.
Keeping Track of Fragments
(Cont’d)
• Another way is to define elementary
fragment size that can pass through every
network.
• When packet fragmented, all pieces equal
to elementary fragment size, except last
one (may be smaller).
85
Fragmentation: Example
• Fragmentation when the elementary data size is 1 byte.
• (a) Original packet, containing 10 data bytes.
• (b) Fragments after passing through a network with maximum packet size of 8 payload bytes plus header.
• (c) Fragments after passing through a size 5 gateway.
Keeping Track of Fragments
• Header contains packet number, number of first
fragment in the packet, and last-fragment bit.
27 0 1 A B C D E F G H I J
27 0 0 A B C D E F G H 27 8 1 I J Packet number Number offirst fragment
Last-fragment bit
(a) Original packet with 10 data bytes.
(b) Fragments after passing through network with maximum packet size = 8 bytes.
87
The Internet
Design Principles for Internet
• Keep it simple.
• Exploit modularity.
• Expect heterogeneity.
• Think robustness.
• Avoid static options and parameters.
• Think about scalability.
89
Internet as Collection of
Subnetworks
IP (Internet Protocol)
• Glues Internet together.
• Common network-layer protocol spoken
by all Internet participating networks.
• Best effort datagram service:
91
IP
• Transport layer breaks data streams into
datagrams; fragments transmitted over Internet,
possibly being fragmented.
• When all packet fragments arrive at destination,
reassembled by network layer and delivered to
transport layer at destination host.
IP Versions
• IPv4: IP version 4.
– Current, predominant version. – 32-bit long addresses.
• IPv6: IP version 6 (aka, IPng).
– Evolution of IPv4.
93
IP Datagram Format
• IP datagram consists of header and data (or
payload).
• Header:
– 20-byte fixed (mandatory) part. – Variable length optional part.
95
IP Options
5-54
IP Addresses
97
IP Addresses (Cont’d)
• Class A: 128 networks with 16M hosts each. • Class B: 16,384 networks with 64K hosts
each.
• Class C: 2M networks with 256 hosts each. • More than 500K networks connected to the
Internet.
• Network numbers centrally administered by
ICANN.
IP Addresses (Cont’d)
99
Scalability of IP Addresses
• Problem: a single A, B, or C address refers to
a single network.
• As organizations grow, what happens?
101
Solution
• Subnetting: divide the organization’s address
space into multiple “subnets”.
• How? Use part of the host number bits as the
“subnet number”.
• Example: Consider a university with 35
departments.
– With a class B IP address, use 6-bit subnet
number and 10-bit host number.
– This allows for up to 64 subnets each with
1024 hosts.
Subnets
103
Subnet Mask
• Indicates the split between network and subnet
number + host number.
Subnet Mask: 255.255.252.0 or
/22 (network + subnet part)
Subnetting: Observations
• Subnets are not visible to the outside world. • Thus, subnetting (and how) is a decision
105
Subnet: Example
• Subnet 1: 10000010 00110010 000001|00 00000001 – 130.50.4.1 • Subnet 2: 10000010 00110010 000010|00 00000001 – 130.50.8.1 • Subnet 3: 10000010 00110010 000011|00 00000001 – 130.50.12.1Problem with IPv4
• IPv4 is running out of addresses.
• Problem: class-based addressing scheme.
– Example: Class B addresses allow 64K hosts.
• More than half of Class B networks have fewer
107
Solution: CIDR
• CIDR: Classless Inter-Domain Routing.
– RFC 1519.
• Allocate remaining addresses in
variable-sized blocks without considering classes.
• Example: if an organization needs 2000
addresses, it gets 2048-address block.
• Forwarding had to be modified.
– Routing tables need an extra entry, a 32-bit
mask, which is ANDed with the destination IP address.
– If there is a match, the packet is forwarded on
that interface.
Network Address Translation
• Another “quick fix” to the address shortage in IP v4. • Specified in RFC 3022.• Each organization gets a single (or small number of)
IP addresses.
– This is used for Internet traffic only.
– For internal traffic, each host gets its own “internal” IP
address.
• Three IP ranges have been declared as “private”. – 10.0.0.0 – 10.255.255.255/8
– 172.16.0.0 – 172.31.255.255/12 – 192.168.0.0 – 192.168.255.255/16
109
NAT – Network Address
Translation
Internet Control Protocols
• “Companion” protocols to IP.
• Control protocols used mainly for signaling
and exchange of control information.
• Examples: ICMP, ARP, RARP, BOOTP, and
111
ICMP
• Internet Control Message Protocol.
• A way to “debug” the Internet and find out
what is happening at routers.
• Defines a dozen different messages that are
generated typically by routers upon some unexpected event.
ICMP Message Types
113
Address Resolution Protocol
• ARP.
• RFC 826.
• Protocol for machines to map IP addresses to
Ethernet addresses.
– This is needed when packet needs to be
delivered to a local host on a LAN (Ethernet).
ARP: Example
. Host 1 wants to send packet to host 2.
. Assume that host 1 knows host 2’s IP address. . Host 1 builds packet with host 2’s IP address.
115
ARP Operation
• Host 1 broadcasts an ARP request on the
Ethernet asking who owns host 2’s IP address.
• Host 2 replies with its Ethernet address. • Some optimizations:
– ARP caches.
– Piggybacking host’s own Ethernet address on
ARP requests.
– Proxy ARP: services ARP requests for hosts
on separate LANs.
Beyond ARP
• ARP solves the problem of mapping IP
address to Ethernet address.
• How do we solve the inverse problem?
– I.e., how to map an Ethernet address to an IP
address?
• Older protocols: RARP (RFC 903) and
BOOTP (RFC 951).
117
DHCP
• Dynamic Host Configuration Protocol. • RFCs 2131 and 2132.
• Assigns IP addresses to hosts dynamically. • DHCP server may not be on the same LAN
as requesting host.
• DHCP relay agent.
DHCP Operation
• Newly booted host broadcasts a DHCP
DISCOVER message.
• DHCP relay agent intercepts DHCP
119
DHCP Operation
DHCP: Address Reuse
• How long should an IP address be allocated? • Issue: hosts come and go.
• IP addresses may be assigned on a “Lease”
basis.