Data Networking Notes
Data Networking Notes
Data Networking Notes
Data Networking
Course Aims
Coursework (20%)
• consisting of 2 Labs with 1 submission
• individual, in-lab marked
• Important! You will need to bring your PIC
microcontroller and I/O boards
3
EEEN30024 Lecture 1
Timetable
Lectures Labs
4
EEEN30024 Lecture 1
Style
Handouts will be given out
– set of slides to be used as lecture notes
– appendix material is examinable unless specifically
stated as excluded
– example sheets – these will be provided on Blackboard
Learning outcomes/resources
– useful for revision, highlight what you should know after
the lecture; pointers to books and web material
Notes
– sometimes I won’t finish a lecture but will expect you to
read and understand it all
– sometimes I will ask quiz-style questions in class to
check your understanding
5
EEEN30024 Lecture 1
Resources
The course unit has been prepared with reference
to:
– James F. Kurose & Keith W. Ross, Computer Networking: A
Top Down Approach, 6th edition, Pearson 2012
– William Stallings, Data and Computer Communications, 9th
Edition, Prentice Hall
6
EEEN30024 Lecture 1
Plan – subject to change
1– Introduction – Internet
2– Application Layer
3– Transport Layer 1
4– Transport Layer 2
5– Network Layer 1
6– Network Layer 2
7– Network Layer 3
8– Data Link Layer 1
9– Data Link Layer 2
10 – Data Link Layer 3
7
EEEN30024 Lecture 1
8
EEEN30024 Lecture 1
A Note About Units...
• Bits/Bytes : • Bandwidth :
– Bits denoted by “b” – uses powers of 10
– Bytes denoted by “B” – tied to MHz which is
– Mb = megabits, 106 hertz
– MB = megabytes – bandwidth of 1 Mbps =
– Kb = kilobits, 106 bits per second
– KB = kilobytes
9
EEEN30024 Lecture 1
Lecture 1
Introduction
Learning Outcomes
– big-picture view of the Internet
– packet switching and circuit switching
– protocol stacks
Learning Resources
K&R – sections 1.1, 1.2.1,
1.3.1 and 1.5
K&R Website for applets:
http://wps.pearsoned.com/ecs_kurose_compnetw_6/216/55463/14198700.cw/
10
EEEN30024 Lecture 1
• How does an application
running on Host 1 “talk” to
Example Network another running on Host 2 ?
Or Host 3 ? Or any other ‘node’
connected to the network ?
• How to analyze/design/build
such networks ?
11
EEEN30024 Lecture 1
Network Software
We shall take a top-down view : simplified 5-layer
model
• network software is
organised as a layered stack
application
• we shall examine each layer
starting from the top transport
• most of the attention will be • each layer consists of
on layers above the physical network one or more protocols
layer
data link • a protocol is a set of
• the physical layer will be rules for exchanging
mentioned later data
physical
13
EEEN30024 Lecture 1
mesh of interconnected
routers
fundamental question:
how is data transferred
through the net?
circuit switching:
dedicated circuit per
call: telephone
network
packet-switching:
data sent through
net in discrete
“chunks”
15
EEEN30024 Lecture 1
Circuit Switching
16
EEEN30024 Lecture 1
Circuit Switching
network resources
(e.g. bandwidth)
divided into "pieces" :
pieces allocated to
calls
resource piece idle if
not used by owning
call (no sharing)
dividing link
bandwidth into
"pieces"
frequency division
time division
17
EEEN30024 Lecture 1
Circuit Switching:
FDM and TDM
Example:
FDM
4 users
frequency
time
TDM
frequency
time
18
EEEN30024 Lecture 1
Circuit Switching:
Numerical example
How long does it take to send a file of 640,000 bits
from host A to host B over a circuit-switched network?
all link speeds: 1.536 Mbps
each link uses TDM with 24 slots/sec
500 msec to establish end-to-end circuit
Packet Switching
each end-to-end data stream resource contention:
divided into packets aggregate resource demand
packets share network can exceed amount
resources available
each packet uses full link congestion: packets queue,
bandwidth wait for link use
resources used as needed store and forward: packets
move one hop at a time
node receives complete
packet before forwarding
20
EEEN30024 Lecture 1
Packet Switching:
Statistical Multiplexing
100 Mb/s C
A Ethernet statistical multiplexing
1.5 Mb/s
B
router:queue of packets link
waiting for output
link
host
D E
Packet-switching:
store-and-forward
L
R R R
Example:
1 Mb/s link
each user: N
• 100 kb/s when “active”
users
• active 10% of time 1 Mbps link
circuit-switching:
10 users
packet switching:
Assuming a group of 35 users,
can potentially support a
larger number of users with each user active for 10% of
depending on the demand the time, probability calculations
tell us the likelihood of 11 or
more simultaneously active
users is very small.
23
EEEN30024 Lecture 1
25
EEEN30024 Lecture 1
a series of steps
26
EEEN30024 Lecture 1
Layering of airline
functionality
ticket (purchase) ticket (complain) ticket
airplane routing airplane routing airplane routing airplane routing airplane routing
27
EEEN30024 Lecture 1
Why layering?
Dealing with complex systems:
explicit structure allows identification,
relationship of complex system’s pieces
layered reference model for discussion
modularization eases maintenance, updating
of system
change of implementation of layer’s service
transparent to rest of system
e.g. change in gate procedure doesn’t affect
rest of system
28
EEEN30024 Lecture 1
Internet protocol stack
application: supporting network
applications application
FTP, SMTP, HTTP
transport: process-process data transport
transfer
TCP, UDP
network
network: routing of datagrams from
source to destination
IP, routing protocols link
link: data transfer between
neighboring network elements physical
Ethernet, 802.111 (WiFi), PPP
physical: bits “on the wire” 5-layer stack
29
EEEN30024 Lecture 1
30
EEEN30024 Lecture 1
Encapsulation
source
message M application
segment Ht M transport
datagram Hn Ht M network
frame Hl Hn Ht M link
physical
link
physical
switch
destination Hn Ht M network
M application Hl Hn Ht M link Hn Ht M
Ht M transport physical
Hn Ht M network
Hl Hn Ht M link router
physical
31
EEEN30024 Lecture 1
32
EEEN30024 Lecture 1
This course unit
• In this course unit we will consider networks
with reference to the 5-layer model given
earlier
– this is essentially the OSI model with the almost
redundant session and presentation layers
removed
– this provides a useful model for thinking about
networks
1
EEEN30024 Lecture 2
Some network
applications
e-mail voice over IP
web real-time video
instant messaging conferencing
remote login cloud computing
P2P file sharing …
multi-user network …
games
streaming stored
video (YouTube)
2
EEEN30024 Lecture 2
Creating a network
application applicatio
n
transport
network
Application architectures
client-server
peer-to-peer (P2P)
hybrid of client-server and P2P
EEEN30024 Lecture 2 4
Client-server architecture
server:
always-on host
permanent IP address
server farms for scaling
clients:
communicate with server
may be intermittently
connected
client/server may have dynamic IP
addresses
do not communicate
directly with each other
EEEN30024 Lecture 2 5
Processes
communicating
process: a program client process: process
running within a host. that initiates
within same host, two
communication
processes server process:
communicate using process that waits to
inter-process be contacted
communication
(defined by OS). aside: applications
processes in different with P2P architectures
hosts communicate by have client processes
exchanging messages & server processes
6
EEEN30024 Lecture 2
Sockets
process sends/receives
host or
messages to/from its socket host or
server
server
socket analogous to door
sending process shoves controlled by
message out door process
app developer
process
sending process relies on socket
socket
transport infrastructure
TCP with
on other side of door TCP with
Internet buffers,
buffers,
which brings message to variables variables
socket at receiving
process
controlled
by OS
API:
choice of transport protocol
choice of parameters
EEEN30024 Lecture 2 7
Addressing processes
to receive messages, identifier includes both IP
process must have an address and port numbers
identifier associated with process on
host.
host device has a unique
32-bit IP address example port numbers:
Q: does IP address of host HTTP server: 80
on which process runs Mail server: 25
suffice for identifying the to send HTTP message to
process? the manchester.ac.uk web
A: No, many processes server:
can be running on same IP address:
host 130.88.203.13
Port number: 80
8
EEEN30024 Lecture 2
Application layer protocol
defines
types of messages public-domain
exchanged, protocols:
e.g., request, response defined in RFCs
message syntax: allows for
what fields in messages interoperability
& how fields are
e.g., HTTP, SMTP
delineated
message semantics proprietary protocols:
meaning of information e.g., Skype
in fields
rules for when and
how processes send &
respond to messages
9
EEEN30024 Lecture 2
10
EEEN30024 Lecture 2
Transport service requirements
of common apps
EEEN30024 Lecture 2 11
EEEN30024 Lecture 2 13
HTTP
overview
HTTP: hypertext
transfer protocol
Web’s application layer PC running
protocol Internet Explorer
client/server model
client: browser that
requests, receives, Server
"displays" Web running
objects Apache Web
server
server: Web server
sends objects* in
Mac running
response to requests Safari
15
EEEN30024 Lecture 2
HTTP request
message
two types of HTTP messages: request,
response
HTTP request message: carriage return character
ASCII (human-readable format) line-feed character
request line
(GET, POST, GET /index.html HTTP/1.1\r\n
HEAD commands) Host: www-net.cs.umass.edu\r\n
User-Agent: Firefox/3.6.10\r\n
Accept: text/html,application/xhtml+xml\r\n
header Accept-Language: en-us,en;q=0.5\r\n
lines Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,utf-8;q=0.7\r\n
carriage return, Keep-Alive: 115\r\n
Connection: keep-alive\r\n
line feed at start
\r\n
of line indicates
end of header lines
EEEN30024 Lecture 2 16
HTTP request message:
general format
request
line
header
lines
body
EEEN30024 Lecture 2 17
21
EEEN30024 Lecture 2
23
EEEN30024 Lecture 2
Distributed, Hierarchical
Database
Root DNS Servers
13 root name
servers
b USC-ISI Marina del Rey, CA
l ICANN Los Angeles, CA worldwide
25
EEEN30024 Lecture 2
EEEN30024 Lecture 2 26
Local Name Server
EEEN30024 Lecture 2 27
resolution
example 2 3
recursive query: 7 6
heavy load? 1 8
EEEN30024 Lecture 2 29
msg header
identification: 16 bit #
for query, reply to
query uses same #
flags:
query or reply
recursion desired
recursion available
reply is authoritative
30
EEEN30024 Lecture 2
DNS protocol, messages
RRs in
response
to query
records for
authoritative servers
additional “helpful”
info that may be used
31
EEEN30024 Lecture 2
32
EEEN30024 Lecture 2
Lecture 2: Summary
application specific protocols:
architectures HTTP, FTP, DNS
client-server typical request/reply
P2P message exchange:
hybrid client requests info or
application service service
requirements: server responds with
data, status code
reliability, bandwidth,
delay message formats:
Internet transport headers: fields giving
info about data
service model
data: info being
connection-oriented,
communicated
reliable: TCP
unreliable, datagrams:
UDP 33
EEEN30024 Lecture 2
Appendix (examinable)
FTP: the file transfer protocol
This image cannot currently be display ed.
FTP commands,
responses
sample commands: sample return codes
sent as ASCII text over status code and phrase
control channel (as in HTTP)
USER username 331 Username OK,
PASS password password required
125 data connection
LIST return list of file in
already open;
current directory
transfer starting
RETR filename retrieves 425 Can’t open data
(gets) file connection
STOR filename stores 452 Error writing
(puts) file onto remote file
host
36
EEEN30024 Lecture 2
Lecture 3:
Transport Layer (1/2)
Learning
Outcomes: understand how
understand transport layer
principles behind protocols in the
transport layer Internet work:
services: UDP: connectionless
multiplexing/ transport
demultiplexing TCP: connection-oriented
transport
reliable data
transfer
EEEN30024 Lecture 3 1
Transport vs
network layer
EEEN30024 Lecture 3 2
Internet transport-layer protocols
reliable, in-order applicatio
n
transport
delivery (TCP) network
data link
physical network
congestion control data link
physical network
data link
flow control physical
connection setup
unreliable, unordered network
data link
physical
delivery: UDP
network
data link
physical
no-frills extension of network
data link
applicatio
"best-effort" IP physical network n
data link transport
Multiplexing/demultiplexing
Demultiplexing at rcv host: Multiplexing at send host:
gathering data from multiple
delivering received segments
sockets, enveloping data with
to correct socket
header (later used for
demultiplexing)
= socket, = process, e.g.
(IP addr + port) web, ftp, …
application P3 P1
P1 application P2 P4 application
host 2 host 3
host 1
EEEN30024 Lecture 3 4
How demultiplexing
works
host receives IP
datagrams 32 bits
each datagram has source source port # dest port #
IP address, destination IP
address
other header fields
each datagram carries 1
transport-layer segment
each segment has source,
destination port number application
host uses IP addresses & data
port numbers to direct (message)
segment to appropriate
socket
port is 16-bit number TCP/UDP segment format
ranging from 0 - 65535
EEEN30024 Lecture 3 5
Connectionless
demultiplexing
when host receives
create sockets with host-
UDP segment:
local port numbers*:
DatagramSocket mySocket1 = new checks destination port
DatagramSocket(12534); number in segment
DatagramSocket mySocket2 = new directs UDP segment to
DatagramSocket(12535); socket with that port
number
when creating datagram
to send into UDP socket, IP datagrams with
must specify different source IP
addresses and/or
(dest IP address, dest port number)
source port numbers
*see Appendix for programming examples directed to the same
socket
EEEN30024 Lecture 3 6
Connectionless
demultiplexing
DatagramSocket serverSocket = new DatagramSocket(6428);
P2 P1
P1
P3
EEEN30024 Lecture 3 7
Connection-oriented
demultiplexing
TCP socket identified server host may
by 4-tuple: support many
source IP address simultaneous TCP
source port number sockets:
dest IP address each socket identified by
dest port number its own 4-tuple
recv host uses all four web servers have
values to direct different sockets for
segment to each connecting client
appropriate socket
EEEN30024 Lecture 3 8
Connection-oriented
demultiplexing
P1 P4 P5 P6 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
EEEN30024 Lecture 3 9
Connection-oriented
demultiplexing :
Multi-Threaded Web Server
P1 P4 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
EEEN30024 Lecture 3 10
UDP:
User Datagram Protocol [RFC 768]
"no frills", "bare bones"
Internet transport Why is there a UDP?
protocol
no connection
"best effort" service, UDP establishment (which can
segments may be: add delay)
lost simple: no connection
delivered out of order state at sender, receiver
to app small segment header
connectionless: no congestion control:
no handshaking UDP can blast away as
between UDP sender, fast as desired
receiver
each UDP segment
handled independently
of others
EEEN30024 Lecture 3 11
UDP: more
often used for 32 bits
streaming
source port # dest port #
multimedia apps Length, in
bytes of UDP length checksum
loss tolerant
segment,
rate sensitive including
header
other UDP uses
DNS
Application
SNMP data
to facilitate reliable (message)
transfer over UDP:
add reliability at
UDP segment format
application layer
but its hard work !
EEEN30024 Lecture 3 12
UDP checksum
Goal: detect "errors" (e.g., flipped bits) in
transmitted segment
Sender: Receiver:
treat segment contents compute checksum of
as sequence of 16-bit received segment
integers check if computed
checksum: addition (1’s checksum correct:
complement sum) of NO - error detected
segment contents YES - no error detected.
sender puts checksum But maybe errors
value into UDP nonetheless?
checksum field More later ….
EEEN30024 Lecture 3 13
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
carry and add
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
EEEN30024 Lecture 3 14
Principles of Reliable
Data Transfer
Relevant in application, transport, link layers
15
EEEN30024 Lecture 3
Principles of Reliable
data transfer
Assumptions:
consider only unidirectional data transfer
but control info will flow on both directions!
underlying channel unreliable
may corrupt bits in packet
so use checksum to detect bit errors
acknowledgements (ACKs/NAKs):
ACK: receiver explicitly tells sender that pkt received
OK
NAK: tells sender that pkt received not OK
sender sends one packet, then waits for
receiver response
EEEN30024 Lecture 3 16
Protocol in Action
sender receiver
send pkt
rcv pkt
send ACK/NAK
rcv ACK/NAK
send pkt
rcv pkt
send ACK/NAK
rcv ACK/NAK
send pkt
rcv pkt
send ACK/NAK
rcv ACK/NAK
Note: NAKs
This is called a Stop-and-Wait
result in pkt
protocol
retransmission
EEEN30024 Lecture 3 17
Principles of Reliable
data transfer
What happens if Handling duplicates:
ACK/NAK corrupted or sender retransmits current pkt
not received? if ACK garbled
sender doesn’t know what solution: sender adds sequence
happened at receiver! number to each pkt
initially 0 and 1
can’t just retransmit:
possible duplicate receiver can now identify and
discard duplicate pkt
receiver uncertain whether
if sender receives NACK for pkt 0 it
the retransmitted pkt is a
will retransmit it. Once ACK is
retransmit or a new pkt received correctly pkt 1 is
Protocols based on transmitted.
retransmission are called similarly if receiver receives corrupted
pkt 0 it will (re)transmit NAK
ARQ:
Automatic Repeat reQuest ARQ-based protocols are characterised
by acknowledgements, timeouts and
re-transmissions
EEEN30024 Lecture 3 18
Principles of Reliable
data transfer
ACKs and NAKs :
If the sequence number is included in the ACK, we
can do away with NAKs:
EEEN30024 Lecture 3 19
Protocol in action
EEEN30024 Lecture 3 22
Protocol in action
EEEN30024 Lecture 3 23
Performance
sender receiver
first packet bit transmitted, t = 0
last packet bit transmitted, t = L / R
EEEN30024 Lecture 3 25
Pipelined protocols
data
Stop-and-Wait
ACK
data
Pipelining
ACKs
Pipelining:
sender allows multiple, "in-flight", yet-to-be-
acknowledged packets
range of sequence numbers must be increased
buffering required at sender and/or receiver
two generic forms of ARQ-based pipelined
protocols: go-Back-N, selective repeat
EEEN30024 Lecture 3 26
Pipelining: increased utilization
sender receiver
first packet bit transmitted, t = 0
last bit transmitted, t = L / R
Increase utilization
by a factor of 3!
EEEN30024 Lecture 3 27
Lecture 3: Summary
principles behind
transport layer services: Next:
multiplexing, flow control
demultiplexing TCP in detail
reliable data transfer
instantiation and
implementation in the
Internet
UDP
TCP
EEEN30024 Lecture 3 28
Appendix: (non-examinable)
Socket programming
Goal: see how a client/server application that
communicate using sockets is built using Java
EEEN30024 Lecture 3 29
host or host or
server server
EEEN30024 Lecture 3 30
Socket programming
with TCP
Client must contact server when contacted by client,
server process must first server TCP creates new
be running socket for server process
server must have created to communicate with client
socket (door) that allows server to talk
welcomes client’s contact with multiple clients
Client contacts server by: source port numbers
used to distinguish
creating client-local TCP
clients)
socket
specifying IP address,
port number of server application viewpoint
process TCP provides reliable, in-order
when client creates transfer of bytes ("pipe")
socket: client TCP between client and server
establishes connection to
server TCP EEEN30024 Lecture 3 31
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
EEEN30024 Lecture 3 32
Stream jargon
stream is a sequence of
characters that flow into
Client
or out of a process.
process
input stream is attached
to some input source for
the process, e.g.,
keyboard or socket.
output stream is
attached to an output
source, e.g., monitor or client TCP
socket. socket
EEEN30024 Lecture 3 33
EEEN30024 Lecture 3 34
Example: Java client (TCP)
import java.io.*;
This package defines Socket()
import java.net.*; and ServerSocket() classes
class TCPClient {
EEEN30024 Lecture 3 35
sentence = inFromUser.readLine();
send line
to server outToServer.writeBytes(sentence + '\n');
}
}
EEEN30024 Lecture 3 36
Example:
Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
EEEN30024 Lecture 3 37
Example:
Java server (TCP), cont..
create output
stream,
attached DataOutputStream outToClient =
to socket new DataOutputStream(connectionSocket.getOutputStream());
read in line
from socket clientSentence = inFromClient.readLine();
EEEN30024 Lecture 3 38
Socket programming with UDP
UDP: no "connection"
between client and
server
application viewpoint:
no handshaking
sender explicitly attaches
UDP provides unreliable transfer
IP address and port of of groups of bytes ("datagrams")
destination to each between client and server
packet
server must extract IP
address, port of sender
from received packet
UDP: transmitted data may
be received out of order,
or lost
EEEN30024 Lecture 3 39
Client/server
socket interaction: UDP
Server (running on hostid) Client
write reply to
serverSocket
specifying read datagram from
client address, clientSocket
port number close
clientSocket
EEEN30024 Lecture 3 40
Example: Java client (UDP)
Client
process Input: receives
packet (recall
Output: sends thatTCP received
packet (recall “byte stream”)
that TCP sent “byte
stream”)
client UDP
socket
EEEN30024 Lecture 3 41
class UDPClient {
public static void main(String args[]) throws Exception
{
create
input stream BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
create
client socket DatagramSocket clientSocket = new DatagramSocket();
EEEN30024 Lecture 3 42
Example:
Java client (UDP), cont.
create datagram
with data-to-send, DatagramPacket sendPacket =
length, IP addr, new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
port
clientSocket.send(sendPacket);
send datagram
to server DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
read datagram
clientSocket.receive(receivePacket);
from server
String modifiedSentence =
new String(receivePacket.getData());
EEEN30024 Lecture 3 43
Example:
Java server (UDP)
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception
create {
datagram socket
DatagramSocket serverSocket = new DatagramSocket(9876);
at port 9876
byte[ ] receiveData = new byte[1024];
byte[ ] sendData = new byte[1024];
while(true)
{
create space for
DatagramPacket receivePacket =
received datagram
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
receive
datagram
EEEN30024 Lecture 3 44
Example:
Java server (UDP), cont
String sentence = new String(receivePacket.getData());
sendData = capitalizedSentence.getBytes();
create datagram
DatagramPacket sendPacket =
to send to client new DatagramPacket(sendData, sendData.length, IPAddress,
port);
write out
datagram serverSocket.send(sendPacket);
to socket }
} end of while loop,
}
loop back and wait for
another datagram
EEEN30024 Lecture 3 45
Lecture 4: Transport Layer
(2/2)
Learning Outcomes:
EEEN30024 Lecture 4 1
Pipelined Protocols
data
data
pipelining
ACKs
pipelining:
sender allows multiple, "in-flight", yet-to-be-
acknowledged pkts
range of sequence numbers must be increased
buffering required at sender and/or receiver
two generic forms of pipelined protocols:
go-Back-N, Selective Repeat
EEEN30024 Lecture 4 2
Pipelined Protocols
Go-back-N: big picture Selective Repeat: big picture
sender can have up to sender can have up to N
N unacknowledged unacknowledged packets
packets in pipeline in pipeline
receiver sends receiver sends individual
individual ACK for each ACK for each packet even if
packet there’s a gap
except when there’s a sender maintains timer for
gap each unacknowledged
sender uses cumulative packet
ACKs
when timer expires,
sender has timer for retransmit only
oldest unacknowledged unacknowledged packet
packet
if timer expires,
retransmit all
unacknowledged packets
3
EEEN30024 Lecture 4
Go-Back-N
Sender:
k-bit seq # in pkt header (thus range of seq #s is 0 -> 2k – 1)
“window” of up to N, consecutive unack’ed pkts allowed
pkts 9 onwards
pkts 1-8
already ack’ed
window slides left to right in the
diagram
EEEN30024 Lecture 4 4
Go-Back-N
Sender:
single timer used
timer running for oldest but not yet acked pkt
if ACK received but there are still additional pkts sent but
not yet acked, the timer is restarted.
timeout(n): retransmit pkt n and all higher seq # pkts in
window
EEEN30024 Lecture 4 5
Go-Back-N
Receiver:
always send ACK for correctly-received pkt with
highest in-order seq #
may generate duplicate ACKs
need only remember next expected seq #
out-of-order pkt:
discard (don’t buffer) -> no receiver buffering!
re-send ACK pkt with highest in-order seq #
EEEN30024 Lecture 4 6
Go-Back-N in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, discard,
012345678 rcv ack0, send pkt4 (re)send ack1
012345678 rcv ack1, send pkt5 receive pkt4, discard,
(re)send ack1
ignore duplicate ACK receive pkt5, discard,
(re)send ack1
pkt 2 timeout
012345678 re-send pkt2
012345678 re-send pkt3
012345678 re-send pkt4 rcv pkt2, deliver, send ack2
012345678 re-send pkt5 rcv pkt3, deliver, send ack3
rcv pkt4, deliver, send ack4
rcv pkt5, deliver, send ack5
EEEN30024 Lecture 4 7
Go-Back-N
Limitations of GBN:
in some scenarios, when window size is large and
delays are long, many pkts can be in the pipeline
a single pkt error can cause the retransmission of a
large number of pkts –the main limitation
alternative –a scheme where the sender only
retransmits those pkts that were in error: Selective
Repeat
EEEN30024 Lecture 4 8
Selective Repeat
receiver individually acknowledges all
correctly received pkts
buffers pkts, as needed, for eventual in-order
delivery to upper layer
sender only resends pkts for which ACK not
received
sender timer for each unACKed pkt
sender window
N consecutive seq #’s
again limits seq #s of sent, unACK’ed pkts
EEEN30024 Lecture 4 9
Selective repeat:
sender, receiver windows
pkts ack’ed
by receiver
pkts ack’ed
by receiver
EEEN30024 Lecture 4 10
Selective repeat:
sender, receiver windows
(reading notes to accompany previous slide)
Sender and receiver windows
• size 14 pkts, numbered left-to-right
Sender Window:
Pkts 1,2,5,8: pkts sent but not yet ack’ed
Pkts 3,4,6,7: pkts already ack’ed
Pkts 9-14: pkts usable but not yet sent
Receiver Window:
Pkts 1,4: pkts expected but not yet
received
Pkts 2,3: pkts received out of order, but
already ack’ed
Pkts 5-14: pkts ready to be accepted
EEEN30024 Lecture 4 11
Selective repeat
sender receiver
data from above : pkt n in
if next available seq # in [rcvbase, rcvbase+N-1]
window, send pkt
send ACK(n)
timeout(n): out-of-order: buffer
resend pkt n, restart in-order: deliver (also
timer deliver buffered, in-order
ACK(n) in pkts), advance window to
[sendbase,sendbase+N-1]: next not-yet-received pkt
mark pkt n as received pkt n in [rcvbase-N,rcvbase-1]
if n smallest unACKed pkt,
ACK(n)
advance window base to
next unACKed seq # otherwise:
ignore
EEEN30024 Lecture 4 12
Selective repeat in
action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, buffer,
012345678 rcv ack0, send pkt4 send ack3
012345678 rcv ack1, send pkt5 receive pkt4, buffer,
send ack4
record ack3 arrived receive pkt5, buffer,
send ack5
pkt 2 timeout
012345678 send pkt2
012345678 record ack4 arrived
012345678 rcv pkt2; deliver pkt2,
record ack5 arrived
012345678 pkt3, pkt4, pkt5; send ack2
EEEN30024 Lecture 4 13
dilemma 0123012
0123012
pkt1
pkt2
0123012
0123012
0123012
example: 0123012 pkt3
X
seq #’s: 0, 1, 2, 3 0123012
pkt0 will accept packet
window size=3 with seq number 0
(a) no problem
receiver sees no
difference in two receiver can’t see sender side.
receiver behavior identical in both cases!
scenarios! something’s (very) wrong!
duplicate data accepted
as new in (b) 0123012 pkt0
pkt1
Note: seq # range must 0123012 0123012
pkt2
be at least twice
0123012 0123012
X 0123012
window size to avoid X
timeout
problem in (b): retransmit pkt0 X
pkt0
window size N <= 2k-1 0123012
will accept packet
with seq number 0
(b) oops!
EEEN30024 Lecture 4 14
Selective Repeat
EEEN30024 Lecture 4 15
TCP: Overview
RFCs: 793, 1122, 1323, 2018, 2581
TCP creates a reliable service
on top of IP’s unreliable service
full duplex data:
point-to-point: bi-directional data flow
one sender, one receiver in same connection
reliable, in-order byte MSS: maximum
stream: segment size
no "message boundaries" connection-oriented:
pipelined: handshaking (exchange
of control msgs)
TCP congestion and flow
initialises the sender &
control set window size
receiver states, before
send & receive buffers data exchange
flow controlled:
sender will not
overwhelm receiver
EEEN30024 Lecture 4 16
TCP segment structure
32 bits
URG: urgent data counting
(generally not used) source port # dest port #
by bytes
sequence number of data
ACK: ACK #
valid acknowledgement number (not segments!)
head not
PSH: push data now len used
UAP R S F Receive window
(generally not used) # bytes the
checksum Urg data pnter
receiver is
RST, SYN, FIN: Options (variable length) willing
connection estab to accept
(setup, teardown
commands)
application
data
Internet
(variable length)
checksum
(as in UDP)
EEEN30024 Lecture 4 17
speed-matching service:
matching the send rate
to the receiving app’s
drain rate
EEEN30024 Lecture 4 19
EEEN30024 Lecture 4 20
TCP Connection Management
Recall: TCP sender, receiver Three way handshake:
establish "connection "
before exchanging data Step 1: client host sends TCP
segments SYN segment to server
initialize TCP variables: specifies initial seq #
seq. #s no data
buffers, flow control info Step 2: server host receives
(e.g. RcvWindow) SYN, replies with ACK
segment
client: connection initiator server allocates buffers
Socket clientSocket = new specifies server initial seq.
Socket("hostname","port number"); #
server: contacted by client Step 3: client receives ACK,
Socket connectionSocket = replies with ACK segment,
welcomeSocket.accept();
which may contain data
EEEN30024 Lecture 4 21
LISTEN LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP ACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received ACK(x)
ESTAB indicates server is live;
send ACK for ACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB
EEEN30024 Lecture 4 22
TCP Connection Management (cont)
close
client closes socket:
clientSocket.close();
timed wait
Step 2: server receives
FIN, replies with ACK.
Closes connection, sends
FIN. closed
EEEN30024 Lecture 4 23
closed
Note: not shown are
the sequence numbers
that accompany the FINs closed
and ACKs
EEEN30024 Lecture 4 24
Principles of Congestion Control
Congestion:
informally: "too many sources sending too
much data too fast for network to handle"
different from flow control!
manifestations:
lost packets (buffer overflow at routers)
long delays (queueing in router buffers)
a major transport layer problem!
EEEN30024 Lecture 4 25
Approaches towards
congestion control
Two broad approaches towards congestion
control:
end-end congestion network-assisted
control: congestion control:
no explicit feedback from routers provide feedback
network to end systems
congestion inferred from single bit indicating
end-system observed congestion (SNA,
loss, delay DECbit, TCP/IP ECN,
approach taken by TCP ATM)
explicit rate sender
should send at
EEEN30024 Lecture 4 26
TCP congestion control:
additive increase, multiplicative decrease
saw tooth
behavior: probing
for bandwidth
time
EEEN30024 Lecture 4 27
RTT
first loss event:
initially cwnd = 1 MSS
double cwnd every
RTT
done by incrementing
cwnd for every ACK
received
summary: initial rate
is slow but ramps up time
exponentially fast
EEEN30024 Lecture 4 29
Refinement:
inferring loss
after 3 dup ACKs:
cwnd is cut in half Philosophy:
window then grows
linearly 3 dup ACKs indicates
but after timeout event: network capable of
delivering some
cwnd instead set to 1
segments
MSS;
window then grows timeout indicates a
exponentially "more alarming"
to a threshold, then congestion scenario
grows linearly
EEEN30024 Lecture 4 30
Refinement
Q: when should the
exponential
increase switch to
linear?
A: when cwnd gets
to 1/2 of its value
before timeout.
Implementation:
variable ssthresh
on loss event, ssthresh
is set to 1/2 of cwnd just
before loss event
EEEN30024 Lecture 4 31
EEEN30024 Lecture 4 31
Lecture 4: Summary
TCP:
segment structure
reliable data transfer
flow control
connection management
congestion control
EEEN30024 Lecture 4 33
Appendix: (examinable)
TCP Round Trip Time (RTT)
and Timeout
Q: how to set TCP Q: how to estimate RTT?
timeout value? SampleRTT: measured time
longer than RTT from segment transmission
but RTT varies until ACK receipt
too short: premature ignore retransmissions
timeout SampleRTT will vary, want
EEEN30024 Lecture 4 34
TCP Round Trip Time
and Timeout
EEEN30024 Lecture 4 35
EEEN30024 Lecture 4 36
TCP Round Trip Time and Timeout
Setting the timeout
EstimatedRTT plus “safety margin”
large variation in EstimatedRTT -> larger safety margin
first estimate of how much SampleRTT deviates from
EstimatedRTT:
DevRTT = (1-)*DevRTT +
*|SampleRTT-EstimatedRTT|
(typically, = 0.25)
EEEN30024 Lecture 4 37
TCP: retransmissions
EEEN30024 Lecture 4 38
TCP: retransmission scenarios
Host A Host B Host A Host B
Seq=92 timeout
timeout
X
loss
SendBase
Seq=92 timeout
= 100
SendBase
= 120
SendBase
= 100 SendBase
= 120
lost ACK scenario premature timeout
time
time
EEEN30024 Lecture 4 39
EEEN30024 Lecture 4 40
Host A Host B
TCP: fast
retransmit X
timeout
time
Figure 3.37 Resending a segment after triple duplicate ACK
EEEN30024 Lecture 4 41
Lecture 5:
Network Layer (1/3)
Learning Outcomes :
EEEN30024 Lecture 5 1
Network Layer
transport segment from application
EEEN30024 Lecture 5 2
Two Key Network-Layer Functions
forwarding: move analogy:
packets from
router’s input to routing: process of
appropriate router planning trip from
output source to dest
routing algorithm
value in arriving
packet’s header
0111 1
3 2
EEEN30024 Lecture 5 4
Network Layer Connection
and Connection-less
Services
datagram network provides network-
layer connection-less service
e.g. the Internet
Network Layer
Connection Service
Example services provided :
call setup, teardown for each call before data can flow
each packet carries VC identifier (not destination host
address) in the header
every router on the path maintains "state" for each
passing connection
link, router resources (bandwidth, buffers) may be
allocated to VC (dedicated resources = predictable
service)
EEEN30024 Lecture 5 7
VC Implementation
a VC consists of:
1. path from source to destination
2. VC numbers, one number for each link along
path
3. entries in forwarding tables in routers along
path
EEEN30024 Lecture 5 8
VC number
Router "A"
VC Forwarding 22 32
12
Table 1
2
3
1 12 3 22
2 63 1 18
3 7 2 17
1 97 3 87
… … … …
EEEN30024 Lecture 5 9
application
5. Data flow begins 6. Receive data application
transport
transport
network 4. Call connected 3. Accept call
network
data link 1. Initiate call
2. incoming call data link
physical
physical
EEEN30024 Lecture 5 10
Datagram Networks
no call setup at network layer
routers: no state about end-to-end connections
no network-level concept of "connection"
packets forwarded using destination host address
packets between same source-destination pair may
take different paths
application application
transport transport
network 1. Send data 2. Receive data network
data link data link
physical physical
EEEN30024 Lecture 5 11
IP destination address in
arriving packet’s header
1
3 2
EEEN30024 Lecture 5 12
Datagram Forwarding Table
Destination Address Range Link Interface
otherwise 3
EEEN30024 Lecture 5 13
Examples:
DA: 11001000 00010111 00010110 10100001 to link interface 0
DA: 11001000 00010111 00011000 10101010 to link interface 1
EEEN30024 Lecture 5 14
Datagram or VC Network: why?
Datagram (Internet) VC (ATM)
data exchange among evolved from telephony
computers human conversation:
"elastic" service, no strict timing,
strict timing req. reliability
"smart" end systems requirements
(computers) need for guaranteed
can adapt, perform service
control, error recovery "dumb" end systems
simple inside network, telephones
complexity at "edge"
complexity inside
many link types network
different characteristics
uniform service difficult
EEEN30024 Lecture 5 15
Link layer
physical layer
EEEN30024 Lecture 5 16
IP Datagram Format
IP protocol version
number 32 bits total datagram
length (bytes)
header length head type of
(bytes) ver service length
.
for
"type" of data len fragment
16-bit identifier flgs fragmentation/
offset reassembly
max number time to upper header
remaining hops live layer 1s complement
checksum
(decremented at sum of the
each router) 32 bit source IP address header fields
upper layer protocol 32 bit destination IP address
to deliver payload to,
e.g. 4=TCP, 17=UDP Options (if any) E.g. timestamp,
record route
how much overhead data taken, specify
with TCP? (variable length, list of routers
to visit.
20 bytes of TCP typically a TCP
20 bytes of IP or UDP segment)
= 40 bytes + app
layer overhead
EEEN30024 Lecture 5 17
IP Fragmentation
& Reassembly
network links have MTU
(Max. Transfer Unit size)
-largest possible link-level
frame. fragmentation:
in: one large
different link types have
datagram
different MTUs out: 3 smaller
IP datagrams larger than datagrams
MTU are fragmented by
router
reassembly
one datagram becomes
several datagrams
"reassembled" only at
final destination host
IP header bits used to
identify, order related
fragments
EEEN30024 Lecture 5 18
IP Fragmentation and
Reassembly
length ID fragflag offset
=4000 =x =0 =0
Example
4000 byte
One large datagram becomes
datagram several smaller datagrams
MTU = 1500
bytes length ID fragflag offset
=1500 =x =1 =0
1480 bytes in
data field length ID fragflag offset
=1500 =x =1 =185
offset =
1480/8 length ID fragflag offset
=1040 =x =0 =370
Applet:
http://wps.aw.com/aw_kurose_network_5/111/28536/7305312.cw/index.html
EEEN30024 Lecture 5 19
IP Addressing: introduction
host/router and
physical link
router’s typically 223.1.3.1 223.1.3.2
have multiple
interfaces
host typically has
one interface 223.1.1.1 = 11011111 00000001 00000001 00000001
IP addresses 223 1 1 1
associated with each
interface
EEEN30024 Lecture 5 20
Subnets
223.1.1.1
IP address: 223.1.2.1
subnet part (high 223.1.1.2
order bits) 223.1.1.4 223.1.2.9
part of IP address
can physically reach
each other without network consisting of 3 subnets
intervening router
EEEN30024 Lecture 5 21
Subnets 223.1.1.0/24
223.1.2.0/24
Recipe
to determine the
subnets, detach each
interface from its
host or router,
creating islands of
isolated networks
each isolated
network is called a 223.1.3.0/24
subnet.
Subnet mask: /24
defines the subnet address
EEEN30024 Lecture 5 22
223.1.1.2
Subnets
223.1.1.1 223.1.1.4
How many?
223.1.1.3
223.1.9.2 223.1.7.0
223.1.9.1 223.1.7.1
223.1.8.1 223.1.8.0
223.1.2.6 223.1.3.27
EEEN30024 Lecture 5 23
IP Addressing: CIDR
subnet host
part part
11001000 00010111 00010000 00000000
200.23.16.0/23
often simply referred to as the "network" part of the address
EEEN30024 Lecture 5 24
IP Addresses: how to get one?
EEEN30024 Lecture 5 25
DHCP:
Dynamic Host Configuration Protocol
EEEN30024 Lecture 5 27
DHCP offer
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 654
Lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255, 67
yiaddrr: 223.1.2.4
transaction ID: 655
time Lifetime: 3600 secs
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 655
Lifetime: 3600 secs
EEEN30024 Lecture 5 28
DHCP: more than IP address
DHCP can return more than just allocated
IP address on subnet:
address of first-hop router for client
name and IP address of DNS sever
network mask (indicating network versus
host portion of address)
EEEN30024 Lecture 5 29
DHCP: example
connecting laptop needs
DHCP DHCP its IP address, addr of
UDP
DHCP
DHCP IP
first-hop router, addr of
DHCP Eth DNS server: use DHCP
Phy
DHCP request
encapsulated in UDP,
DHCP
encapsulated in IP,
DHCP DHCP encapsulated in 802.1
DHCP UDP 168.1.1.1 Ethernet frame
IP
Ethernet frame broadcast
DHCP
Eth router
(dest: FFFFFFFFFFFF) on
DHCP
Ethernet demuxed to IP
demuxed, UDP demuxed
to DHCP
EEEN30024 Lecture 5 30
DHCP: example
encapsulation of DHCP
DHCP DHCP server, frame forwarded
DHCP UDP to client, demuxing up
DHCP IP to DHCP at client
DHCP Eth router client now knows its IP
DHCP
Phy (runs DHCP) address, name and IP
address of DSN server,
IP address of its first-
hop router
EEEN30024 Lecture 5 31
Lecture 5 :
Summary
Introduction
Virtual circuit and
datagram networks
IP: Internet Protocol
IP Datagram
Fragmentation/re- Next:
assembly
IP address allocation
CIDR
NAT
Subnets
ICMP
IPv4 addressing
IPV6
DHCP
EEEN30024 Lecture 5 32
Lecture 6:
Network Layer (2/3)
Learning Outcomes :
EEEN30024 Lecture 6 1
IP address Allocation:
ICANN
global authority
manages DNS root servers
assigns domain names, resolves disputes
allocates addresses to regional Internet
registries, e.g. RIPE (Europe), ARIN (Asia),
etc
• they in turn allocate blocks of addresses to
regional/national ISPs (Nominet in the UK)
ISP = Internet Service Provider
EEEN30024 Lecture 6 2
Hierarchical addressing allows
efficient advertisement of routing
information
Example
ISPs divide up allocated block to individual customers
Customer 0
200.23.16.0
Customer 1
Allocated block:
200.23.18.0 200.23.16.0/20
Customer 2
200.23.20.0 . Fly-By-Night-ISP
.
. .
. National
Customer 7 . registry
200.23.30.0
Allocated block:
ISPs-R-Us
199.31.0.0/16
EEEN30024 Lecture 6 3
IP Address Allocation
The ISP’s customers are allocated a portion of
the address space
ISP's block 11001000 00010111 00010000 00000000 200.23.16.0/20
In this example the ISP divides its address block into eight
equal-sized address blocks, each of which is allocated to a
customer. Each customer has 32 – 23 = 9 bits of address space
for addressing individual hosts, i.e. 29 = 512 hosts.
Q: is a customer likely to have a single LAN with this many hosts ?
EEEN30024 Lecture 6 4
Address Subnetting
EEEN30024 Lecture 6 5
Address Subnetting
Starting with
11001000 00010111 00010000 00000000 200.23.16.0/23
subnet 0 : 200.23.16.0/28
host 1: 11001000 00010111 00010000 00000001 200.23.16.1
host 14:11001000 00010111 00010000 00001110 200.23.16.14
subnet 1 : 200.23.16.16/28
host 1: 11001000 00010111 00010000 00010001 200.23.16.17
host 14:11001000 00010111 00010000 00011110 200.23.16.30
subnet 2 : 200.23.16.32/28
subnet 3 : 200.23.16.48/28
…etc
Host addresses 0 and 15 reserved. Why ?
EEEN30024 Lecture 6 6
Subnet Example
To the outside, this looks like a single network -the subnetting is not visible .
E.g. 200.23.16.44 is routed to subnet 2, but this is unknown to the sender.
200.23.16.0/28 200.23.16.48/28
200.23.16.16/28 200.23.16.64/28
200.23.16.32/28 200.23.16.80/28
.
.
.
. .
. .
. The main router’s tables contains
not all subnets shown in example entries for each subnet
EEEN30024 Lecture 6 7
Subnet Mask
A router uses a subnet mask to extract all
the bits of an address except the host.
EEEN30024 Lecture 6 8
How a router uses
the subnet mask
To determine which subnet to route a packet to,
the subnet mask is ANDed with the address.
Suppose
IP address 200.23.16.44
mask /28
Gives
11001000.00010111.00001000.00101100 AND
11111111.11111111.11111111.11110000 gives
11001000.00010111.00001000.00100000
- 200.23.16.32
Thus within this network, subnet 2 is used
• the highlighted bits give the subnet number
EEEN30024 Lecture 6 9
Classful Addressing
IP addresses were originally used in 5 classes – so
called classful addressing:
EEEN30024 Lecture 6 10
Classful Addressing
EEEN30024 Lecture 6 11
Private IP Addresses
Within class A, B and C networks there are defined ranges
of private addresses (using CIDR notation –see later):
class A: 10.0.0.0/8
class B: 172.16.0.0/12
class C: 192.168.0.0/16
EEEN30024 Lecture 6 12
NAT:
Network Address Translation
rest of local network
Internet (e.g., home network)
10.0.0/8 10.0.0.1
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
EEEN30024 Lecture 6 13
NAT:
Network Address Translation
Motivation: local network uses just one IP address
as far as outside world is concerned:
range of addresses not needed from ISP: just
one IP address 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).
EEEN30024 Lecture 6 14
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.
EEEN30024 Lecture 6 15
NAT:
Network Address Translation
NAT translation table 1: host 10.0.0.1
2: NAT router WAN side addr LAN side addr sends datagram to
changes datagram
138.76.29.7, 5001 10.0.0.1, 3345 128.119.40.186, 80
source addr from
10.0.0.1, 3345 to …… ……
138.76.29.7, 5001,
updates table S: 10.0.0.1, 3345
D: 128.119.40.186, 80
10.0.0.1
1
S: 138.76.29.7, 5001
2 D: 128.119.40.186, 80 10.0.0.4
10.0.0.2
138.76.29.7 S: 128.119.40.186, 80
D: 10.0.0.1, 3345 4
S: 128.119.40.186, 80
D: 138.76.29.7, 5001 3 10.0.0.3
4: NAT router
changes datagram
3: Reply arrives dest addr from
dest. address: 138.76.29.7, 5001 to 10.0.0.1, 3345
138.76.29.7, 5001
EEEN30024 Lecture 6 16
NAT:
Network Address Translation
16-bit port-number field:
60,000 simultaneous connections with a
single LAN-side address!
NAT is controversial:
routers should only process up to layer 3
violates end-to-end argument
• NAT possibility must be taken into
account by app designers, e.g., P2P
applications
address shortage should instead be solved
by IPv6
EEEN30024 Lecture 6 17
EEEN30024 Lecture 6 18
NAT traversal problem
EEEN30024 Lecture 6 19
2. connection to
relay initiated 1. connection to
by client relay initiated
by NATed host 10.0.0.1
3. relaying
Client
established
138.76.29.7 NAT
router
EEEN30024 Lecture 6 20
ICMP:
Internet Control Message Protocol
used by hosts & routers to
communicate network-level
information Type Code description
0 0 echo reply (ping)
error reporting:
3 0 dest. network unreachable
unreachable host,
3 1 dest host unreachable
network, port, protocol
3 2 dest protocol unreachable
echo request/reply 3 3 dest port unreachable
(used by ping) 3 6 dest network unknown
network-layer "above" IP: 3 7 dest host unknown
ICMP msgs carried in IP 4 0 source quench (congestion
datagrams control - not used)
ICMP message: type, code 8 0 echo request (ping)
plus first 8 bytes of IP 9 0 route advertisement
datagram causing error 10 0 router discovery
11 0 TTL expired
‘ping’ program sends ICMP
12 0 bad IP header
type 8 code 0 to a host
destination host replies with a
type 0 code 0 ICMP reply
EEEN30024 Lecture 6 21
EEEN30024 Lecture 6 22
IPv6
EEEN30024 Lecture 6 23
data
32 bits
EEEN30024 Lecture 6 24
Other Changes from IPv4
EEEN30024 Lecture 6 25
EEEN30024 Lecture 6 26
Tunneling
A B E F
Logical view: tunnel
A B E F
Physical view:
IPv6 IPv6 IPv4 IPv4 IPv6 IPv6
EEEN30024 Lecture 6 27
Tunneling
A B E F
Logical view: tunnel
A B C D E F
Physical view:
IPv6 IPv6 IPv4 IPv4 IPv6 IPv6
data data
A-to-B: E-to-F:
B-to-C: B-to-C:
IPv6 IPv6
IPv6 inside IPv6 inside
IPv4 IPv4
EEEN30024 Lecture 6 28
Lecture 6 : summary
Further principles
behind network
layer services:
IP address Next:Routing
allocation algorithms
Link state
Subnetting
Distance Vector
NAT Hierarchical routing
ICMP
IPV6
EEEN30024 Lecture 6 29
Lecture 7:
Network Layer (3/3)
Learning Outcomes :
Routing algorithms
Link State
Distance Vector
EEEN30024 Lecture 7 1
Routing
Context for lecture
packet
EEEN30024 Lecture 7 2
Forwarding and Routing
routing algorithm
value in arriving
packet’s header
0111 1
3 2
EEEN30024 Lecture 7 3
Routing Algorithm
classification
Global or decentralized Static or dynamic?
information? Static:
Global:
routes change slowly
all routers have complete
topology, link cost info
over time
"link state" algorithms Dynamic:
Decentralized: routes change more
router knows physically- quickly
connected neighbors, link
periodic update
costs to neighbors
iterative process of in response to link
computation, exchange of cost changes
info with neighbors
"distance vector"
algorithms
EEEN30024 Lecture 7 4
Link Cost
Cost of a link
- path between a pair of of hops – i.e.
number of routers to be traversed
physical distance
delay
• queue size for link
• actual delay – use echo packets
throughput of the link
• high performance links being ‘cheaper’
than low performance links
monetary cost
EEEN30024 Lecture 7 5
Static Routing
Permanent routes established based on the
least cost paths
where cost might be based on hop count,
distance, link performance, etc
Firstly, get network with costs
Construct a table for network that gives
the least cost (‘shortest’) path between
each pair of nodes
Determination of shortest path is given by using
algorithm’s like Dijkstra’s algorithm or the
Bellman-Ford algorithm
• both are considered in this lecture
EEEN30024 Lecture 7 6
from
Static Routing A B C D E F G H
Example
A - A A C B D D G
Central Routing B B - B B B E D F
Table
to C C C - C F D D G
4 E 2
D C D D - F D D G
9 E B E D F - E D F
7 B F 8
F C E D F F - D F
8
A 8 2 H G C D D G F D - G
9
C 1 D 5 H C E D G F H H -
4
G
link
costs
EEEN30024 Lecture 7 7
A B C D E F G H
D Next D Next D Next D Next D Next D Next D Next D Next
A - A A A A A C A B A D A D A G
B B B - B B B B B B B E B D B F
C C C C C - C C C F C D C D C G
D C D D D D D - D F D D D D D G
E B E E E D E F E - E E E D E F
F C F E F D F F F F F - F D F F
G C G D G D G G G F G D G - G G
H C H E H D H G H F H H H H H -
EEEN30024 Lecture 7 8
Dynamic Routing:
Dijkstra’s algorithm
A Link State algorithm
4 E 2
9
7 B F 8
8
A 8 2 H
9
C 1
D 5
4
G 9
EEEN30024 Lecture 7
Dijkstra’s algorithm
Net topology, link costs known to all nodes
accomplished via "link state broadcast"
all nodes have same info.
Computes least cost paths from one node
(‘source’) to all other nodes
gives forwarding table for that node.
4 E 2
9
7 B F 8
8
A 8 2 H
9
C 1 D 5
4
G
EEEN30024 Lecture 7 10
Dijkstra’s algorithm
The algorithm uses the following notation
(Cost, Previous Node) e.g. (7,A) assigned to a node is a
cost of 7 and an indication that the cost associated with
the route is from the neighbour A
Dijkstra’s algorithm
Mark the node that is being considered as a
permanent node
a permanent node is shown unshaded
Mark its neighbours with the cost of the route
to that node (∞,-)
4 E 2 (∞,-)
(7,A)
9
7 B F 8 (∞,-)
8
A 8 2 H
9
C D 5
1 4
(9,A) (∞,-) G
(∞,-)
12
EEEN30024 Lecture 7
Dijkstra’s algorithm
From the set of nodes that are not permanent, choose the node
with the lowest cost and make this a permanent node
in this case B.
From the set of nodes connected to this new permanent node
examine all neighbouring nodes
if they are marked permanent, don’t consider further (e.g.. A
in the example)
if not permanent, compute a cost, based on the cost
associated with the node and the link cost to the
neighbouring node
• if the computed cost is less than the cost associated with
the neighbouring node, update the information at the
neighbour – using the computed cost and the identify of
the permanent node
– e.g. when considering B update information for D, E
and F
• if the computed cost is greater than or equal to the cost at
the neighbouring node, leave neighbouring node
unchanged
Repeat until all nodes are permanent
EEEN30024 Lecture 7 13
Dijkstra’s algorithm
(11,B)
4 E 2 (16,B)
(7,A)
9
7 B F 8 (∞,-)
8
A 8 2 H
9
C D 5
1 4
(9,A) (15,B) G
(∞,-)
EEEN30024 Lecture 7 14
Dijkstra’s algorithm
(11,B)
4 E 2 (16,B)
(7,A)
9
7 B F 8 (∞,-)
8
A 8 2 H
9
C D 5
1 4
(9,A) (10,C) G
(∞,-)
EEEN30024 Lecture 7 15
Dijkstra’s algorithm
(11,B)
4 E 2 (12,D)
(7,A)
9
7 B F 8 (∞,-)
8
A 8 2 H
9
C D 5
1 4
(9,A) (10,C) G
(14,D)
EEEN30024 Lecture 7 16
Dijkstra’s algorithm
(11,B)
4 E 2 (12,D)
(7,A)
9
7 B F 8 (∞,-)
8
A 8 2 H
9
C D 5
1 4
(9,A) (10,C) G
(14,D)
EEEN30024 Lecture 7 17
Dijkstra’s algorithm
(11,B)
4 E 2 (12,D)
(7,A)
9
7 B F 8 (20,F)
8
A 8 2 H
9
C D 5
1 4
(9,A) (10,C) G
(14,D)
EEEN30024 Lecture 7 18
Dijkstra’s algorithm
(11,B)
4 E 2 (12,D)
(7,A)
9
7 B F 8 (19,G)
8
A 8 2 H
9
C D 5
1 4
(9,A) (10,C) G
(14,D)
EEEN30024 Lecture 7 19
Dijkstra’s algorithm A
D Next
The routing tables A -
can now be
developed for A by B B
following the paths C C
D C
E B
F C
The procedure is G C
repeated for each
router. H C
EEEN30024 Lecture 7 20
Dijkstra’s algorithm, discussion
Algorithm complexity: n nodes
each iteration: need to check all nodes
n(n+1)/2 comparisons: O(n2)
more efficient implementations possible: O(nlog2n)
Oscillations possible:
e.g., link cost = amount of carried traffic
1 A 1+e A A A
2+e 0 0 2+e 2+e 0
D 0 0 B D 1+e 1 B D B D B
0 0 1+e 1
0 e 0 0 1 1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
EEEN30024 Lecture 7 21
EEEN30024 Lecture 7 22
Discover neighbours
On booting up, send a HELLO packet to
neighbours, neighbours respond by giving
back their network address
we’ll simply use a single character id to simplify the
issue here
4 E 2
9
7 B F 8
8
A 8 2 H
9
C D 5
1 4
G
23
EEEN30024 Lecture 7
4 E 2
9
7 B F 8
8
A 8 2 H
9
C D 5
1 4
G
24
EEEN30024 Lecture 7
Build Link State Packets
Packets can be 4 E 2
constructed at each 9
7 B F 8
router that indicate
the delays to its 8
A 8 2 H
neighbours, e.g..
9
C 1 D 5
4
G
A B C D E F G H
Seq. Seq. Seq. Seq. Seq. Seq. Seq. Seq.
Age Age Age Age Age Age Age Age
B 7 A 7 A 9 B 8 B 4 B 9 D 4 F 8
C 9 C 8 B 8 C 1 F 2 D 2 H 5 G 5
D 8 D 1 F 2 E 2
E 4 G 4 H 8
F 9
25
EEEN30024 Lecture 7
Solution
Assign an age to the packet as well a sequence
number
Decrement the age once per second until it has
reached zero when the information associated with
that packet is discarded
• age is also decremented by each router as the
packet passes through
EEEN30024 Lecture 7 27
EEEN30024 Lecture 7 28
Distance Vector Routing
Distance vector routing is a dynamic technique
that will respond to changes.
A router has a routing table with
a row for each router in the network
in each row it has two entries
• the preferred port over which to reach the router
• the cost of doing so
– number of hops, time delay, queue length
etc…
A router periodically sends its table to its
neighbours and receives copies of its
neighbour’s tables.
Using this information and knowing the cost to
its neighbours the router can update its table.
EEEN30024 Lecture 7 29
4 E 2
9
7 B F 8
8
A 8 2 H
9
C D 5
1 4
G
EEEN30024 Lecture 7 30
Entry obtained by summing, the cost from D
to the router and selecting the lowest value.
Update Table for D Note: B could be routed via B or F
Distance Vector
Routing
4 E 2
Good news travels fast. 9
7 B F 8
Consider the
8
addition of Router I A 8 2 H
connected to Router G 9
with a cost of 3. C 1 D 5
4
G
The addition of the new router
and its cost are established after
3 I
3 message exchanges after G has established
cost to I
1. G’s new table propagated to D and H.
2. D’s new table propagated to B, C, and F, H’s to F.
3. A is informed of I by B and C, E is informed of I
by F and B.
32
EEEN30024 Lecture 7
Distance Vector
Routing
4 E 2
What happens if a link
9
goes down? 7 B F 8
Suppose the link to I is 8
now removed. A 8 2 H
G advertises cost to I as 9
C 1 D 5
4
and receives messages from D G
and H advertising the cost as 7 and 8 respectively, I
G updates its table to reflect the cost from D, i.e. a cost of 11.
Focussing on D and G
D updates its cost to I to be 15 (message from G)
G updates its cost to I to be 19 (message from D)
D updates its cost to I to be 23 (message from G)
• a slow count to infinity!
"Bad news travels slowly."
EEEN30024 Lecture 7 33
EEEN30024 Lecture 7 34
Comparison of LS and DV
algorithms
Message complexity Robustness: what happens if
LS: with n nodes, E links, router malfunctions?
O(nE) msgs sent LS:
DV: exchange between node can advertise
neighbors only incorrect link cost
convergence time varies each node computes only
its own table
Speed of Convergence
LS: O(n2) algorithm requires
DV:
O(nE) msgs DV node can advertise
may have oscillations incorrect path cost
DV: convergence time varies each node’s table used by
others
may be routing loops
• error propagates
count-to-infinity problem through network
EEEN30024 Lecture 7 35
Proprietary
• e.g. IGRP: Interior Gateway Routing Protocol (Cisco)
EEEN30024 Lecture 7 36
Lecture 7: Summary
Routing
algorithms
Link state
Distance
Vector
EEEN30024 Lecture 7 37
Lecture 8:
Data Link Layer (1/3)
Learning Outcomes :
Introduction
Terminology:
hosts and routers are nodes
communication channels
that connect adjacent nodes
along communication path
are links
wired links
wireless links
LANs
layer-2 packet is a frame,
encapsulates datagram
EEEN30024 Lecture 8 3
EEEN30024 Lecture 8 5
combination of
hardware, software,
firmware
EEEN30024 Lecture 8 6
Adaptors Communicating
datagram datagram
controller controller
frame
Error Detection
EDC= Error Detection and Correction bits (redundancy)
D = Data protected by error checking, may include header
fields
otherwise
EEEN30024 Lecture 8 8
Error Checking
Single Bit Parity:
Detect single bit errors
Internet Checksum
Detect multiple bit errors in packets
-more later
EEEN30024 Lecture 8 9
Multiple Access
Links and Protocols
Two types of "links":
point-to-point, e.g.
PPP for old-style Internet dial-up access
point-to-point link between Ethernet switch and host
broadcast (shared wire or medium), e.g.
old-fashioned Ethernet
802.11 wireless LAN
humans at a
shared wire (e.g., shared RF shared RF cocktail party
cabled Ethernet) (e.g., 802.11 WiFi) (satellite) (shared air, acoustical)
EEEN30024 Lecture 8 10
Multiple Access
protocols
single shared broadcast channel
two or more simultaneous transmissions by
nodes: interference
collision if node receives two or more signals at the same
time
EEEN30024 Lecture 8 11
EEEN30024 Lecture 8 12
MAC Protocols: a taxonomy
EEEN30024 Lecture 8 13
EEEN30024 Lecture 8 14
Channel Partitioning MAC
protocols: FDMA
FDMA: frequency division multiple access
channel spectrum divided into frequency bands
each station assigned fixed frequency band
unused transmission time in frequency bands go idle
example: 6-station LAN, 1,3,4 have packets, but
frequency bands 2,5,6 idle
frequency bands
FDM cable
EEEN30024 Lecture 8 15
EEEN30024 Lecture 8 16
Slotted ALOHA
Assumptions: Operation:
all frames same size when node obtains fresh
time divided into frame, transmits in next
equal size slots (time slot
to transmit 1 frame) if no collision: node
nodes start to can send new frame
transmit only slot in next slot
beginning if collision: node
nodes are retransmits frame in
synchronized each subsequent slot
if 2 or more nodes
with probability p
transmit in slot, all until success
nodes detect collision
EEEN30024 Lecture 8 17
Slotted ALOHA
Pros Cons
single active node can collisions, wasting slots
continuously transmit at idle slots
full rate of channel nodes may be able to
highly decentralized: detect collision in less
only slots in nodes need than time to transmit
packet
to be in sync
clocks have to be
simple synchronized
EEEN30024 Lecture 8 18
Slotted Aloha efficiency
Efficiency : long-run
fraction of successful max efficiency: find p*
that maximizes
slots Np(1-p)N-1
(many nodes, all with for many nodes, take
many frames to send) limit of Np*(1-p*)N-1 as
suppose: N nodes with N goes to infinity, gives:
many frames to send, each Max efficiency = 1/e = 0.37
transmits in slot with
probability p
probability that given node
has success in a slot = At best: channel
p(1-p)N-1 used for useful
prob that any node has a transmissions 37%
success = Np(1-p)N-1 of time!
result from application of
Poisson distribution
EEEN30024 Lecture 8 19
EEEN30024 Lecture 8 20
CSMA (Carrier Sense Multiple Access)
EEEN30024 Lecture 8 21
collisions
collisions can still
occur:
propagation delay means
two nodes may not hear
each other’s transmission
collision:
entire packet transmission
time wasted
note:
role of distance & propagation
delay in determining collision
probability
EEEN30024 Lecture 8 22
CSMA/CD (Collision Detection)
CSMA/CD:
carrier sensing, deferral as in CSMA
collisions detected within short time
colliding transmissions aborted, reducing channel
wastage
collision detection:
easy in wired LANs: measure signal strengths, compare
transmitted, received signals
• example Ethernet
difficult in wireless LANs: received signal strength
overwhelmed by local transmission strength
human analogy: the polite conversationalist
EEEN30024 Lecture 8 23
EEEN30024 Lecture 8 24
"Taking Turns" MAC protocols
channel partitioning MAC protocols:
share channel efficiently and fairly at high
load
inefficient at low load: delay in channel
access, 1/N bandwidth allocated even if
only 1 active node!
random access MAC protocols
efficient at low load: single node can fully
utilize channel
high load: collision overhead
"taking turns" protocols
look for best of both worlds!
EEEN30024 Lecture 8 25
concerns:
polling overhead
latency slaves
single point of failure
(master)
EEEN30024 Lecture 8 26
"Taking Turns" MAC protocols
T
Token passing:
control token
passed from one
(nothing
node to next to send)
sequentially. T
token message
concerns:
token overhead
latency
single point of failure
(token) data
EEEN30024 Lecture 8 27
IEEE 802
LLC and MAC
LLC sub-layer
provides an interface to high level protocol (network layer)
– multiplexing and demultiplexing higher level protocols
over the LAN
optionally manages flow and error control
e.g. transport layer-style connection-oriented,
acknowledged/unacknowledged connection services
MAC sub-layer
assembles frames for transmission with address and error-
detection fields
disassembles frames on reception performing address
recognition and error detection
manages access to the shared transmission medium
• the major task of MAC
EEEN30024 Lecture 8 30
IEEE 802 – LLC and MAC
Why two layers?
LLC is independent of network, and will
work with a number of different
implementations of the MAC layer
• LLC (IEEE 802.2) can be used with IEEE 802.3
(Ethernet), IEEE 802.5 (Token Ring), IEEE 802.11
(Wireless LAN)
EEEN30024 Lecture 8 31
Lecture 8 Summary
EEEN30024 Lecture 8 32
Lecture 9:
Data Link Layer (2/3)
Learning Outcomes :
Be able to explain error correction and error
detection and be able to use the following
with arbitrary data
Parity Checking (1D, 2D)
Hamming Code
CRC
Internet Checksum
• 1’s complement of 1’s complement
sum of words
Reading: Stallings "Data and Computer Communications",
Chapter 6, sections 6.2 – 6.4
EEEN30024 Lecture 9 1
Introduction
/Recap
Terminology:
hosts and routers are nodes
communication channels
that connect adjacent nodes
along communication path
are links
wired links
wireless links
LANs
layer-2 packet is a frame,
encapsulates datagram
Error Detection
and Correction
Detecting errors require that redundant, check bits have to
be added to blocks of data
redundant as they do not carry data
Error Detection
having sufficient check bits to detect that a frame is in
error
error correction (if required) managed by retransmission of
frame
an error-detecting code
Error Correction
Transmit rather more check bits (a greater degree of
redundancy) to provide a means for errors to be corrected
An error-correcting code, also known as forward error
correction
EEEN30024 Lecture 9 4
Block Codes
A message of m bits
A set of n check bits
Gives rise to a c-bit (m + n) codeword
2m valid codewords can be transmitted from the set of
2c codewords
a received codeword that is in the set of 2c-2m invalid
codewords indicates an error
For each pair of codewords that can be produced, we
can compute a useful quantity called the Hamming
distance
i.e. the number of bits that differ between each pair
e.g. 00011 and 01101 have a Hamming distance of 3
• XOR and count 1s
The minimum Hamming distance between all pairs of
codewords in the set of 2m valid codewords is the
Hamming distance for the coding scheme
EEEN30024 Lecture 9 5
Hamming Distance:
Error Correction and Error
Detection
If dc is the number of bits in error that can be
corrected in the codeword and
dd is the number of bits that can be
detected in the codewords
For a code with a minimum Hamming
distance dmin we can note that
for error detection purposes, dd = dmin – 1
for error correction purposes,
By inspection dmin is 3
any 1-bit and 2-bit errors can be detected
invalid codewords would be produced
any single bit error can be corrected
the codeword received will be ‘closer’ to that of
the original data than any of the other 3
codewords and that any 2-bit error cannot be
corrected with confidence
since the codeword received may be ‘closer’ to
another valid codeword
EEEN30024 Lecture 9 7
EEEN30024 Lecture 9 8
Parity Checking
EEEN30024 Lecture 9 9
Parity Checking
A parity bit produces a Hamming Distance
of 2
for example if m is 2 we transmit (using even
parity)
• 00 as 000
• 01 as 011
• 10 as 101
• 11 as 110
giving the codewords 000, 011, 101, 110 and a
Hamming distance of 2
therefore the code can be used to detect single
bit errors, but provide no error correction
EEEN30024 Lecture 9 10
Extending Parity Checking
to two dimensions
When a burst error occurs (affecting several bits),
parity checking has a probability of 0.5 of detecting
the error
performance can be improved if the data to be sent
is considered as an x by y matrix
the parity is computed for each of the y columns in
addition to the x rows
data is sent on a row by row basis
provided that the burst error is not greater than x bit
durations and that only one burst error occurs in the
time to send the block, the burst error will be
detected
even where multiple errors occur, the probability of
each of the x columns having the correct parity is 0.5
(2-1) and the probability of a block being in error and
being accepted is 2-x
EEEN30024 Lecture 9 11
Parity row
Hamming Code*
Number all bits from 1 to c starting at the
most significant bit (left hand bit)
the bits that are powers of two, 1, 2, 4, 8,
16, etc … are check bits that record parity
Even or odd parity may be used
the other bits hold the m bits of data and
each contributes to the check bits that
contribute to the value, for example
3 is checked by bits 2 and 1,
6 is checked by bits 4 and 2
13 is checked by bits 8, 4 and 1
*additional information about Hamming Codes can be found in Chapter 3
of "Computer Networks" by Andrew S. Tanenbaum.
EEEN30024 Lecture 9 14
Hamming Code Coding
Example
EEEN30024 Lecture 9 15
EEEN30024 Lecture 9 16
Hamming Code Error
Correction: Example
EEEN30024 Lecture 9 17
Hamming Code
EEEN30024 Lecture 9 18
Error Detecting
Codes
Error correcting codes seem quite appealing,
but there is a large overhead.
EEEN30024 Lecture 9 19
Error Detecting
Codes (continued)
Parity checking may be used (especially in the
2D form described earlier (which gives rise to
more check bits)), but the more common
forms of error checking is by
EEEN30024 Lecture 9 20
Detecting Errors
– Block Coding
EEEN30024 Lecture 9 21
CRC: Cyclic
Redundancy Code
Given a m-bit message the transmitter generates an n-
bit sequence called the Frame Check Sequence
(FCS)
the resulting c-bit frame (m followed by n) is exactly
divisible by a predetermined number (the generator
sequence)
known to both sender and receiver
the receiver receives the incoming frame, divides by
the generator sequence
if the remainder is zero, there is no error in the
frame
if the remainder is not zero, there is some error
thus the FCS is appended to the message to give the
property that when the frame is divided by the
generator sequence there will be no remainder
EEEN30024 Lecture 9 22
Cyclic Redundancy
Code
CRCs are often expressed in polynomial form
the bits in a word represent the coefficients of a
polynomial of a dummy variable (x)
For example, the byte 10100101 represents
EEEN30024 Lecture 9 23
CRC - Modulo 2
Arithmetic
Addition and Subtraction
Binary addition – with no carries XOR
Binary subtraction – with no borrows
XOR
Thus
0011 + 0011 –
0110 0110
0101 0101
EEEN30024 Lecture 9 24
CRC - Modulo 2 Arithmetic
Explanation
Define
T = c-bit frame to be transmitted
D = m-bit block of data, the message, the first m
bits of T
F = the n-bit FCS, the last n bits of T
P = a pattern of n + 1 bits, this is the divisor
• The generator sequence
EEEN30024 Lecture 9 25
EEEN30024 Lecture 9 27
EEEN30024 Lecture 9 28
CRC - Modulo 2 Arithmetic
Example - Creation Q
Message (D) = 11111001
2n D
1101/10011010000
10011010 1101
Generator (P) = P 1001
1101 1101
1000
1101
R = F, so send 2n D 1011
+R 1101
1100
R = 101 1101
i.e. 10011010101 1000
1101
101 R
EEEN30024 Lecture 9 29
Divide T by P 11111001
1101/10011010101
1101
No remainder so no 1001
error 1101
1000
1101
1011
1101
1100
1101
1101
1101
0
EEEN30024 Lecture 9 30
CRC - Modulo 2 Arithmetic
Example – Reception – with
errors
Remainder is not 11110100
1101/10010000101
zero, hence error 1101
detected 1000
1101
1010
1101
1110
1101
1101
1101
001
EEEN30024 Lecture 9 31
Simpler Checksums
Internet Checksum
To give an example, work with bytes
rather than 16-bit words and assume
that 4 bytes are to be transmitted in
addition to the checksum
4 bytes are
10101010
00001111
01011010
10010010
36
Internet Checksum Creation
Add together the 4 bytes, 2 Take 1’s complement
at a time, using 1’s (i.e. invert all the
complement modulo 2 bits)
arithmetic; any carry out is
added to the LSB: 01011001
-this is the checksum
10101010 +
00001111
10111001 +
01011010
100010011 +
1
Carry out 00010100 +
added to
the LSB 10010010
10100110
EEEN30024 Lecture 9 37
Checksum checking
–no error
Take data and It’s 1’s complement so the
checksum byte and carry is added to the least
add together using 1’s significant end
complement addition 11111110 +
10101010 + 1
00001111 11111111
01011010
10010010 the result is 11111111 this
01011001 is one of the two 1’s
111111110 complement
1111 1 1 representations of zero (-0)
1 so the checksum is correct
EEEN30024 Lecture 9 38
Checksum checking
– with error
Take data and checksum It’s 1’s complement so the
byte and add together carry is added to the least
using 1’s complement significant end
addition 00111110 +
10101010 + 10
01001111 01000000
01011010 11111
10010010 the result is 01000000 this
01011001 is not 0,
1000111110 so the checksum indicates
an error
1 11 1 1
1 1
EEEN30024 Lecture 9 39
Lecture 9 Summary
Error /detection
correction
EEEN30024 Lecture 9 40
Lecture 10:
Data Link Layer (3/3)
Learning Outcomes :
EEEN30024 Lecture 10 1
LAN
(wired or = adapter
wireless)
71-65-F7-2B-08-53
58-23-D7-FA-20-B0
0C-C4-11-6F-E3-98
EEEN30024 Lecture 10 3
LAN Address
(more)
MAC address allocation administered by IEEE
manufacturer buys portion of MAC address space
(to assure uniqueness)
analogy:
(a) MAC address: like National Insurance
Number (UK)
(b) IP address: like postal address
MAC flat address ➜ portability
can move LAN card from one LAN to another
IP hierarchical address NOT portable –can change
address depends on IP subnet to which node is attached
DHCP, etc
EEEN30024 Lecture 10 4
ARP: Address Resolution
Protocol
Question: how to find MAC Each IP node (host,
address of a host, knowing router) on LAN has an
that host’s IP address? in-memory ARP table
ARP table: IP->MAC
137.196.7.78
address mappings for
1A-2F-BB-76-09-AD
some LAN nodes
137.196.7.23 < IP address; MAC address;
137.196.7.14
TTL>
LAN TTL (Time To Live):
71-65-F7-2B-08-53 time after which
58-23-D7-FA-20-B0
address mapping will
be forgotten (typically
0C-C4-11-6F-E3-98 20 min)
137.196.7.88
EEEN30024 Lecture 10 5
ARP protocol:
Same LAN (network)
A wants to send A caches (saves) IP->MAC
datagram to B, and B’s address pair in its ARP table
MAC address not in A’s until information becomes old
ARP table. (times out)
A broadcasts ARP query information that times out
packet, containing B's IP removed from the table
address (unless refreshed)
dest MAC address = table often viewable from
FF-FF-FF-FF-FF-FF command line program,
all machines on LAN e.g. ‘arp –a’ on Windows
receive ARP query ARP is "plug-and-play" :
B receives ARP packet, nodes create their ARP
replies to A with its (B's) tables without intervention
MAC address from an administrator
frame sent to A’s MAC
address (unicast)
EEEN30024 Lecture 10 6
Addressing:
routing to another LAN
Walkthrough: send datagram from A to B via R.
-assume Ethernet connections
focus on addressing - at both IP (datagram) and MAC layer
(frame)
assume A knows B’s IP address
assume A knows IP address of first hop router, R (how?)
assume A knows MAC address of first hop router interface
(how?)
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 7
Addressing:
routing to another LAN
A creates IP datagram with IP source A, destination B
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 8
Addressing:
routing to another LAN
frame sent from A to R frame received at R,
datagram removed,
MAC src: 74-29-9C-E8-FF-55
passed up to IP
MAC dest: E6-E9-00-17-BB-4B
IP src: 111.111.111.111
IP dest: 222.222.222.222
IP IP
Eth Eth
Phy Phy
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 9
Addressing:
routing to another LAN
R forwards datagram with IP source A, destination B
R creates link-layer frame
with B's MAC address as
destination, frame contains MAC src: 1A-23-F9-CD-06-9B
MAC dest: 49-BD-D2-C7-56-2A
A-to-B IP datagram IP src: 111.111.111.111
IP dest: 222.222.222.222
IP
IP Eth
Eth Phy
Phy
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 10
Addressing:
routing to another LAN
R forwards datagram with IP source A, destination B
R creates link-layer frame
with B's MAC address as MAC src: 1A-23-F9-CD-06-9B
MAC dest: 49-BD-D2-C7-56-2A
dest, frame contains A-to- IP src: 111.111.111.111
B IP datagram IP dest: 222.222.222.222
IP
IP Eth
Eth Phy
Phy
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 11
Addressing:
routing to another LAN
R forwards datagram with IP source A, destination B
R creates link-layer frame with MAC src: 1A-23-F9-CD-06-9B
B's MAC address as destination, MAC dest: 49-BD-D2-C7-56-2A
IP src: 111.111.111.111
frame contains A-to-B IP IP dest: 222.222.222.222
datagram IP
Eth
Phy
A B
R
111.111.111.111
222.222.222.222
74-29-9C-E8-FF-55
49-BD-D2-C7-56-2A
222.222.222.220
1A-23-F9-CD-06-9B
EEEN30024 Lecture 10 12
Ethernet
"dominant" wired LAN technology:
cheap ~ £20 for NIC
first widely used LAN technology
simpler, cheaper than token LANs and ATM
kept up with speed race: 10 Mbps – 10 Gbps
Metcalfe’s Ethernet
sketch
EEEN30024 Lecture 10 13
Star topology
bus topology popular through mid 1990s
all nodes in same collision domain (can collide with
each other)
today: star topology prevails
active switch in center
each “spoke” runs a (separate) Ethernet protocol
(nodes do not collide with each other)
switch
EEEN30024 Lecture 10 14
Ethernet Frame Structure
Sending adapter encapsulates IP datagram (or
other network layer protocol packet) in
Ethernet frame
Preamble:
7 bytes with pattern 10101010 followed by
one byte with pattern 10101011
used to synchronize receiver, sender clock
rates
EEEN30024 Lecture 10 15
EEEN30024 Lecture 10 16
Ethernet:
Unreliable, connectionless
EEEN30024 Lecture 10 17
CSMA/CD efficiency
Tprop = max prop delay between 2 nodes in
LAN
ttrans = time to transmit max-size frame
efficiency goes to 1
as tprop goes to 0
as ttrans goes to infinity
better performance than ALOHA: and simple,
cheap, decentralized!
EEEN30024 Lecture 10 20
802.3 Ethernet Standards:
Link & Physical Layers
MAC protocol
application and frame format
transport
network 100BASE-TX 100BASE-T2 100BASE-FX
link 100BASE-T4 100BASE-SX 100BASE-BX
physical
Ethernet Switch
A link-layer device: more properly termed a
Link Layer Switch
stores and forwards Ethernet frames
Has a switch table
• examines incoming MAC addresses and selectively
forwards frames to one or more outgoing links,
according to table entries.
self-learning
• no need to configure; “plug and play”.
Transparent
hosts are unaware of presence of switch.
EEEN30024 Lecture 10 22
Link Layer Switch
Hosts have dedicated A
full-duplex
connection to switch. F B
Ethernet protocol is
6 1 2
used but no collisions
hosts can transmit 5 4 3
simultaneously E C
• the switch buffers
packets.
D
switch with six interfaces
(1,2,3,4,5,6)
EEEN30024 Lecture 10 23
EEEN30024 Lecture 10 24
Manchester Encoding
used in 10BaseT
each bit has a transition
allows clocks in sending and receiving nodes
to synchronize to each other
no need for a centralized, global clock among nodes
more later…
EEEN30024 Lecture 10 25
Lecture 10
Summary
Data Link Layer 3/3
EEEN30024 Lecture 10 26
Lecture 11:
Embedded Systems
Networks
Learning Outcomes :
Be able to explain the following :
Introduction to Embedded Systems IO
Memory-mapped v Ported I/O
Synchronous and Asynchronous Serial Bus
Protocols
Serial and Parallel bus architectures
Design issues for serial networks
UARTS; bit rates v baud rates; “bit-banging”
EEEN30024 Lecture 11 1
Introduction
Embedded computing system: a system that includes
a programmable computer but is not itself a general-
purpose computer.
EEEN30024 Lecture 11 2
Embedded Systems
Some characteristics
• sophisticated functionality
• real-time operation
• low cost
• low power
• compact design
EEEN30024 Lecture 11 3
EEEN30024 Lecture 11 4
Network-on-Chip (NoC)
processor1 processor2
cache cache
special-purpose
memory memory ...
processor
Network
EEEN30024 Lecture 11 5
Network-on-Chip (NoC)
applies the concepts of
large-scale networks to
embedded system-on- PE PE PE
chip
S S
packet or virtual circuit
switching on a single PE PE PE
integrated circuit
S S
packets are routed from
via network ‘fabric’ PE PE PE
consisting of switches
(‘routers’) and S S
inteconnection links
(wires) PE processing element
S switch
EEEN30024 Lecture 11 6
Embedded Systems I/O
μC needs to talk with I/O
devices such as D/A Address
converter, EEPROM, LEDs… Data
μC
Read
Memorymapped I/O Write
devices are mapped to
specific memory Memory I/O Device
locations just like RAM
uses load/store
instructions just like Address
accesses to memory Data
μC Port Select
Ported I/O Read
special bus line and Write
instructions I/O Port
one or more Memory
addressable registers I/O Device
for control and data I/O Port usually included on-board microcontroller
adapted from Intel EEEN30024 Lecture 11 7
Memory-mapped I/O
With memory-mapped I/O, one address space FFFF
is divided into two parts Memory
programming simpler
I/O looks just like
memory read/write
must decide which
memory addresses are
used for I/O devices
devices have relatively
high pin count for
data/address/control
• increases package size
and overall cost
EEEN30024 Lecture 11 9
Ported I/O
FFFFFFFF
Aspects of Ported I/O
EEEN30024 Lecture 11 10
I/O Bus Architecture
Busses can be categorised in different ways:
serial/parallel, electrical characteristics, protocol used, etc.
E.g. by synchronous/asynchronous :
Synchronous bus transfers occur in relation to
successive edges of a clock
Asynchronous bus transfers bear no particular timing
relationship
Semisynchronous bus Operations/control initiate
asynchronously, but data transfer occurs synchronously
Bus
Master (CPU) CS
unstable stable unstable stable
Data I-fetch data
access time
image: Intel EEEN30024 Lecture 11 12
Asynchronous Bus Protocol
No system clock used
Useful for systems where CPU
and I/O devices run at
different speeds Address
Example: there's
I see you
got it
some
Master puts address and Master data
Bus Arbitration
What happens if multiple
devices want access to the
bus? Bus
Scheme 1: Every device
connects to the bus request line
and the first one there gets it μC Device 1 Device 2 Device 3
EEEN30024 Lecture 11 15
Bus Architecture:
Serial v Parallel
Speed
On a parallel bus the speed of an 8-bit data transfer is in theory 8-times
faster than serial data transfer. In practice clock skew reduces the speed
to that of the slowest (lagging) link. Data only needs to be placed in a
latch and copied onto the data bus; most serial data transfer must be
converted from/to parallel form but is usually done on-chip at high speed.
parallel port
Output 1
Output 2
Output 3
.
μC .
Cost
transmission channel costs such as data bus cable length, data bus
buffers, interface connectors, area occupied on microcontroller or printed
circuit board (PCB), parallel data communication is costlier.
Bus length
Noise and interference between the parallel lines (‘crosstalk’), worsens
with the length of the communication link. This places an upper limit on
the length of a parallel data connection that is usually shorter than a serial
connection. Bandwidth and signal-to-noise ratio are generally lowered by
these effects. A serial bus usually allows devices to be attached over much
longer distances. Parallel bus more commonly seen on-chip or on the
same PCB.
EEEN30024 Lecture 11 17
Serial Networks
Examples of serial networks :
EEEN30024 Lecture 11 19
bus termination
• both ends terminated with matching impedances (differential
signalling)
• unterminated, or terminated at one end only (typical with single-ended
busses)
EEEN30024 Lecture 11 20
Embedded I/O devices for serial
communications
Data within a microcontroller is mostly transferred in parallel
• there is need for parallel->serial and serial->parallel conversion
• carried out by a UART -basis for most serial communication hardware
-Universal Asynchronous Receiver Transmitter
• originally handled by a dedicated chip, nowadays integrated on-chip
8 8
TRANSMITTER RECEIVER
EEEN30024 Lecture 11 21
UART
Commonly used for asynchronous communication
• between an embedded system and another device or embedded system
• supports protocols such as RS232, RS422, RS423 (considered later);
these support voltages of up to +/- 25V; UART does the voltage level
shifting required.
• supports simplex, half- and full-duplex protocols
• simplex : data sent in one direction only
• half-duplex : data sent in both directions, but not at the same time
• full-duplex : data can be sent in both directions simultaneously
Tclock1 Rclock2
Transmitter Receiver
Data Bus Data Bus
Rclock1 Tclock2
Receiver Transmitter
UART UART
EEEN30024 Lecture 11 22
UART
UART is also responsible for framing the data
• E.g. 1 start bit, 8 data bits 1 stop bit
– depends on actual protocol
• an additional parity bit optionally before stop bit
• start and stop bits used to separate frames
Data
bits
Message
10110110001
UART UART
EEEN30024 Lecture 11 23
MicroChip USART
Basically a UART with support for synchronous serial
communication in half-duplex mode
clock is sent with data (Tx pin)
mode of operation selectable through software control of a register
baud rate settable through the Baud Rate Generator –a component
of the USART
EEEN30024 Lecture 11 24
Bit Rate vs. Baud Rate
Bit Rate: number of data bits are transmitted per second
serial link speed, e.g. 9600bps to 1.5 Mbps, typically
Baud Rate: number of symbols are transmitted per second
rate at which signal on line changes
a symbol may be represented by a voltage level, a sine
wave’s frequency or phase, etc.
These may be different
Extra symbols (channel changes) may be inserted for
framing, error detection, acknowledgment, etc. These
reduce the bit rate
A single symbol might encode more than one bit. This
increases the bit rate.
• e.g. multilevel signaling, quadrature amplitude
modulation, phase amplitude modulation, etc.
• other encoding schemes considered later
EEEN30024 Lecture 11 25
"Bit Banging"
When a microcontroller has only limited (e.g. single UART) or
no support for adding devices to a serial interface
Select one or more spare I/O pins for “transmit” and “receive”
transmitting is done by alternating the transmit pin at the desired
baud rate
receiving is done by sampling the receiver pin at a regular interval
-e.g. if the rate is 9600bps the sampling interval is 1/9600 s
(104us)
EEEN30024 Lecture 11 26
"Bit Banging"
Pseudo-code for algorithm for sending a byte:
start
repeat
make Tx pin Low (Start Bit)
wait for duration corresponding to baud rate
send data bit
wait for duration corresponding to baud rate
until all eight data bits haven’t been sent
send Stop Bit
wait for duration corresponding to baud rate.
make Tx pin High
stop
EEEN30024 Lecture 11 27
"Bit Banging"
EEEN30024 Lecture 11 28
Lecture 12:
Asynchronous Serial
Networks
Learning Outcomes :
To compare and contrast synchronous and
asynchronous digital communication
To explain the purpose, characteristics and
applications of the following Asynchronous
Serial Networks
RS-232
RS-422
RS-485
USB, FireWire
EEEN30024 Lecture 12 1
Asynchronous and
Synchronous Transmission
EEEN30024 Lecture 12 2
Asynchronous Transmission
no common clock between sender and receiver
data are transmitted one character at a time
each character is 5 to 8 bits in length
receiver has the opportunity to resynchronize at
the beginning of each new character
Asynchronous Transmission
RS-232
EEEN30024 Lecture 12 6
RS-232
Digital data exchange between a centrally located
mainframe computer and a remote computer terminal,
or between two terminals without a computer involved.
originally over an analog (voice) telephone line, hence
modems at each end that connected ‘data terminal
equipment’ (DTE) and ‘data communication equipment’
(DCE). Lots of different manufacturers hence the need for
a standard to ensure compatibility.
typical speeds (baud): 9600, 14400, 19200, 38400,
57800, 115200
DB25 : 25-pin
connector
RS-232 Signals
Common 25 pin “D-shell” connector pin-out used for
asynchronous data communications.
not all signals strictly necessary –usually a common subset are used
9-pin connector more common nowadays (called “DB9”)
Pin Signal
1 PGND (Protective Ground)
2 TXD (Transmit Data)
3 RXD (Receive Data)
4 RTS (Ready To Send)
5 CTS (Clear To Send)
6 DSR (Data Set Ready)
(serial port - PC side)
7 SG (Signal Ground)
8 CD (Carrier Detect)
“DB25” connector
20 DTR (Data Terminal Ready)
22 RI (Ring Indicator)
EEEN30024 Lecture 12 8
RS-232 Signals
Architecturally RS-232 is a
DB9 : 9-pin
bi-directional point to point connector
link.
(serial port - PC side)
EEEN30024 Lecture 12 9
EEEN30024 Lecture 12 10
RS-232 Hardware Flow Control
Prevent transmitter overflowing receiver’s buffer.
receiver
CTS No
RTS
CTS Yes
TD
Send RD
character
EEEN30024 Lecture 12 11
Steps:
1. DTE (computer) sets DTR to make a 7. DTE has no further data to send; drops
connection with the DCE (modem). RTS.
2. DCE accepts and replies with DSR. 8. DCE acknowledges by dropping CTS.
3. DTE sends RTS. 9. DTE ready to send data again.
4. DCE is ready and replies with CTS. 10. DCE acknowledges with CTS.
5. DCE’s buffers are full; drops CTS to 11. DTE has no further data to send.
signal to DTE to stop sending data. 12. DCE drops CTS.
6. DCE’s buffers cleared; raises CTS again. 13. DTE drops DTR to terminate
connection.
14. DCE drops DSR.
receiver
x-off
x-on
data
transmission
EEEN30024 Lecture 12 13
RS-232 Cables
• When two serial ports are connected, the data rate, the
number of data bits, whether parity is used, the type of
parity, and the number of stop bits must be set properly
and identically on each UART.
EEEN30024 Lecture 12 14
RS-232 Interconnects
EEEN30024 Lecture 12 15
RS-232 Interconnects
minimal null-modem
EEEN30024 Lecture 12 17
RS-232 Physical
RS-232 Logic Levels:
Mark (logic 1) -25 to –3 volts
Space (logic 0) +25 to +3 volts
RS-232
TTL logic TTL
Logic levels Logic
levels
levels
RS-232 uses a single voltage
relative to ground to indicate data:
called ‘single-ended’ signalling
Least
Significant Bit
Space
when the transmitter is not
Mark sending anything, it holds
the line at mark level,
start bit data bits
also called idle level.
EEEN30024 Lecture 12 18
RS-232 Limitations
EEEN30024 Lecture 12 19
RS422 Standards
The RS-422 standard defines a balanced (or differential) data
communications interface using two separate wires for each
signal
used in point-to-point links and uses same signals as RS-232 with
a different electrical interface specification
Due to the high noise immunity of the RS-422 standard, high
data speeds and long distances can be achieved.
The RS-422 specification allows reliable serial data
communications for:
distances of up to 1200 meters
data rates of up to 10 Mbps
-6V to +6V nominal signal swing
up to ten receivers can be attached
RS-422 uses two separate twisted pairs (Tx and Rx)
the transmitter translates the single input signal into a pair
of outputs that are driven 180° out of phase.
the receiver, a differential amplifier, recovers the signal as the
difference in the voltages on the two lines.
EEEN30024 Lecture 12 20
RS-485
EEEN30024 Lecture 12 21
RS-485
EEEN30024 Lecture 12 22
RS-485 v RS-422
USB :
Universal Serial Bus
Aim: unify the plethora of PC interconnect methods to
PCs that existed in the 1990s
vdd,gnd
4-wire serial bus
uses differential signalling
a number of versions since 1995
now USB 3.0
speed up to 480Mbps
hot-pluggable devices (plug & play)
supports up to 127 external devices
limited by 7-bit address
bus provides power and ground D+, D-
EEEN30024 Lecture 12 24
USB Bus topology
PC
USB devices
PC ‘host’ serves as master
Devices cannot initiate data
transfers
must wait to be asked by the
host
no direct communication
between USB devices
Each device has a unique
address
data is sent in packets
When the host is transmitting
each device on the bus sees it
data is relayed/repeated by
the hub(s) down the chain
EEEN30024 Lecture 12 26
USB data flow
hardware/software
interface
EEEN30024 Lecture 12 27
EEEN30024 Lecture 12 28
FireWire
Used by Apple
Based on IEEE 1394
a serial bus interface designed for high speed
communications
‘competition’ to USB
similar speeds
plug & play
support up to 63 devices
differential signalling and provides power
comparison to USB
USB is host-based(must be connected to computer),
Firewire is peer to peer (two devices can be connected
directly)
EEEN30024 Lecture 12 29
Lecture 13:
Examples of Synchronous
Serial Networks
Learning Outcomes :
SPI Bus
I2C-Bus
EEEN30024 Lecture 13 1
Introduction
EEEN30024 Lecture 13 2
SPI Bus
Serial Peripheral Interface
A four-wire interface used primarily for synchronous serial
communication of a host processor and peripherals
SS
EEEN30024 Lecture 13 4
SPI
In general devices can transmit and receive at the same
time
e.g. an EEPROM
some devices are receive-only, e.g. a display
EEEN30024 Lecture 13 5
SPI
Scenario with single master and multiple slaves:
SCLK Slave 2
MOSI
MISO
MOSI: Master Out Slave In SS2
-data is sent out if the device is a Master,
but received in if it’s a slave
MISO: Master In Slave Out
-data is received in if the device is a
Master, but sent out if it’s a slave
SCLK: Serial Clock –data is shifted on
either the rising or falling edge
SCLK Slave 3
SS: Slave Select –usually this is active
low. MOSI
MISO
EEEN30024 Lecture 13 6
SPI
Scenario with single master and multiple slaves in a cascade
(or 'daisy-chain') configuration:
Master SCLK SCLK Slave 1
(microcontroller) MOSI MOSI
MISO MISO
SS SS1
SCLK Slave 2
MOSI
MISO
MOSI: Master Out Slave In SS2
-data is sent out if the device is a Master,
but received in if it’s a slave
MISO: Master In Slave Out
-data is received in if the device is a
Master, but sent out if it’s a slave
SCLK: Serial Clock –data is shifted on
either the rising or falling edge
SCLK Slave 3
SS: Slave Select –usually this is active
low. MOSI
MISO
EEEN30024 Lecture 13 7
SPI
The master generates the slave select signals using
general-purpose discrete input/output pins
on-chip subsystem logic (eg MSSP on the MicroChip PIC).
SPI is simple
no communication protocol
-no specification for master-slave dialog
-no built-in addressing scheme
-no acknowledgement mechanism or flow control
-the clock can vary without disrupting the data. The data rate
will simply change along with the changes in the clock rate –
useful when the microcontroller is being clocked imprecisely,
such as by an RC oscillator.
SDO
RC5/SDO
SDI
SSPSR RC4/SDI
EEEN30024 Lecture 13 9
SPI
Advantages:
Fast and simple
fast for point-to-point connections with full duplex
communication
suited to data that is streamed rather than record-oriented
no addressing/simple to implement
widely supported
Disadvantages :
multiple master configurations are complicated
no acknowledgement ability
no inherent arbitration
no flow control
short distances only (e.g. same PCB)
EEEN30024 Lecture 13 10
I2C-Bus
Inter-Integrated Circuit Bus
EEEN30024 Lecture 13 11
I2C
+Vss
Rp Rp
Device 1 Device 2 Device 3
Microcontroller
SCL
SDA
Gnd
output
2-wire serial bus – serial data (SDA) and serial clock (SCL)
EEEN30024 Lecture 13 12
I2C
typically 5V
I2C Protocol
Devices are either masters or slaves
master initiates data transfers
master always drives SCL
multiple-master configurations possible but not common
The start sequence and stop sequence are the only places where
the SDA (data) is allowed to change while the SCL (clock) is high.
When data is being transferred, SDA must remain stable and not change
whilst SCL is high. Start and Stop mark the beginning and end of a
transaction with the slave device.
EEEN30024 Lecture 13 14
I2C Signals
• Start – high-to-low transition of the SDA line while SCL line is high
• Stop – low-to-high transition of the SDA line while SCL line is high
• Data – transition takes place while SCL is slow, valid while SCL is high
Data are placed on SDA and transferred in sequences of 8 bits starting with
the MSB (Most Significant Bit). The SCL line is then pulsed high, then low.
For every 8 bits transferred, the device receiving the data sends back an
acknowledge Bit (ACK), so there are actually 9 SCL clock pulses to transfer
each byte. If the ACK bit sent by the receiving device is low, then it has received
the data and is ready to accept another byte. If it does not drive the line low,
and leaves it high then it is indicating it cannot accept any further data and the
master should terminate the transfer by sending a stop sequence.
EEEN30024 Lecture 13 15
I2C Signals
EEEN30024 Lecture 13 16
I2C Protocol
Typical flow:
1. Send Start sequence
2. Send the I2C address of the slave
3. Send an internal register address (if necessary)
4. Send the data byte(s)
5. Send the Stop sequence
EEEN30024 Lecture 13 17
I2C transmissions
single-byte write
single-byte read
EEEN30024 Lecture 13 18
I2C Bus Arbitration
Sender listens while transmitting.
If two masters generate a Start at the same time there will be
a conflict. Arbitration is done by monitoring SDA:
I2C
Clock Stretching
If the slave is not ready, the master must wait for the slave
if the slave is another microcontroller this could take a long
time, e.g. tens of microseconds.
rather than have the master issue lots if unnecessary
clock pulses, the slave is allowed to hold the clock line
down, called clock stretching
once the slave has the data ready it releases the clock
EEEN30024 Lecture 13 20
I2C
Advantages:
EEEN30024 Lecture 13 21
I2C
Disadvantages :
EEEN30024 Lecture 13 22
I2C: MicroChip PIC
RC4/SDI/SDA
support for SPI is
provided through C
SSPSR library functions, e.g.
RC3/SCL
OpenI2C()
WriteI2C()
SSPBUF ReadI2C()
StopI2C()
-see lab 2 notes
SSPCON1 Select master/slave
mode
EEEN30024 Lecture 13 23
Lecture 14:
CAN, LIN
Learning Outcomes :
CAN
LIN
EEEN30024 Lecture 14 1
Introduction
Industrial embedded systems applications often have
real time characteristics that impact on communications
requirements
time-critical aspects where a guaranteed response
within strict time constraints is required
reliability and safety are extremely important
EEEN30024 Lecture 14 2
CAN
Two-wire (twisted pair), bidirectional serial-bus
differential signalling
CAN
Originally developed in 1989 by Bosch for automotive use
Mostly used in passenger cars, but also lots of non-automotive uses
-farm and construction machinery
-printing machines, railway systems
-building automation,
-production and packaging equipment
-domestic goods, etc…
Standardized internationally:
- CAN 2.0A: ISO11519 — low speed, <250Kbps("Basic CAN")
- CAN 2.0B: ISO11898 — high speed, <1Mbps ("Full CAN")
Scalable network
no limit in principle to the
number of nodes, although
typically< 40 per network
CAN Protocol
CAN does not specify a
physical interface
only the data link layer
partially implemented by
higher-level protocols,
e.g. CANOpen, J1939,
DeviceNet
CAN Node
EEEN30024 Lecture 14 8
CAN Data Flow
The node produces a 'dominant' value by simultaneously driving the "C_HI" line high and
the "C_LO line" low. That is, it actively creates a positive differential voltage between
these signals.
A 'recessive state' is created on the CAN bus whenever all nodes on the network leave
the "C_HI" and "C_LO" lines in a high-impedance state. That causes the termination
resistors to passively create a zero differential voltage between these signals.
The CAN bus must be terminated to provide the recessive state — and to eliminate wave
reflections at ends of the bus wires. Typical DC bus terminations are in the 60-Ohm
range, and the twisted-pair cables have a 120-Ohm characteristic impedance.
C_HI C_HI
C_LO C_LO
Node A Node B
EEEN30024 Lecture 14 10
CAN Data Frame
• Notes: 29-bits for CAN 2.0B; ID extend bit allows for >2000 nodes on the bus; Rem Req
(“remote request”) for requesting the transmission of a specific identifier from another node.
CAN Arbitration
Example 1:
EEEN30024 Lecture 14 12
CAN Arbitration
EEEN30024 Lecture 14 13
CAN Arbitration
EEEN30024 Lecture 14 14
CAN Arbitration
EEEN30024 Lecture 14 15
CAN Arbitration
Node 3 wins
EEEN30024 Lecture 14 16
CAN Arbitration
Example 2:
recessive
Node A
dominant
Node B
Node C
bus state
EEEN30024 Lecture 14 17
EEEN30024 Lecture 14 18
CAN Bus Error Checking
Five different kinds of error checking are performed by all nodes
EEEN30024 Lecture 14 19
EEEN30024 Lecture 14 21
CAN
EEEN30024 Lecture 14 22
LIN
LIN – Local Interconnect Network
slower and low cost alternative to CAN
speed up to 20Kbps
EEEN30024 Lecture 14 23
LIN
CAN and LIN typically co-exist in automobile environments:
LIN Frame:
EEEN30024 Lecture 14 25
LIN
LIN is byte oriented
data is sent byte at a time
each byte field contains a start bit (dominant), 8 data bits, and a
stop bit (recessive) –similar to how a UART transmits data
data bits are sent LSB first
the Message Header contains a synch break that serves as a start of
frame, followed by a synch byte that serves to help the slaves
determine the time between two rising edges to determine the
Master’s transmission speed
the ID field is one byte long, and includes parity bits; it carries the
message identifier (message type), and information about the sender
and receiver:
EEEN30024 Lecture 14 26
Lecture 15
Physical Layer:
Coding of Digital Data
Learning Outcomes :
references:
Stallings –Section 5.1, also Appendix16A
EEEN30024 Lecture 15 1
Requirements
Return to Zero-Level
(RZ)
in RZ the voltage returns to zero
unlike NRZ, where the voltage is constant during
the bit interval
0V
Unipolar
power is proportional to:
Bipolar
power is proportional to:
5
EEEN30024 Lecture 15
Timing Information
6
EEEN30024 Lecture 15
Asynchronous Data
Transfer
Synchronous Data
Transmission
data is transferred as block of many bits of data
synchronisation is by clock recovery from the data
using a phase locked loop
8
EEEN30024 Lecture 15
Loss of synchronisation
9
EEEN30024 Lecture 15
10
EEEN30024 Lecture 15
Efficient use of bandwidth
11
EEEN30024 Lecture 15
12
EEEN30024 Lecture 15
Data and Modulation Rate
13
EEEN30024 Lecture 15
14
EEEN30024 Lecture 15
Efficient use of coding
Spectral Properties
16
EEEN30024 Lecture 15
Tolerance to
Wiring Inversion
When complex network installations are made it
is possible for the polarity of the wires to become
reversed
17
EEEN30024 Lecture 15
Non-Return to
Zero-Invert on Ones (NRZI)
18
EEEN30024 Lecture 15
NRZ codes generally
19
EEEN30024 Lecture 15
Multilevel Binary
Pseudoternary
1 no signal; 0 +ve and –ve alternately
20
EEEN30024 Lecture 15
Multilevel Binary
Overall average of signal value should be 0V
hence no dc drift
Where long run of 1s (AMI) or 0s (pseudoternary),
transitions occur to give clock synchronisation
however, long runs of 0s (AMI) or 1s (pseudoternary) do not
have this property and synchronisation may be lost
however, some schemes (e.g. ISDN) insert additional bits to
force transitions
Bandwidth is used efficiently
Data Rate = Signal Rate
However, the receiver has to be able to detect 3 levels
(rather than 2) in presence of noise
compared with NRZ codes either
increase SNR (e.g. increase power by 3dB)
Biphase Manchester
and Differential Manchester
Manchester
+ve going transition for 1, -ve going transition for 0
opposite transitions can be specified
always a transition in the middle of the data bit
Differential Manchester
transition at beginning of bit for 0, no transition for 1
always a mid-bit transition
22
EEEN30024 Lecture 15
Biphase Manchester
and Differential Manchester
23
EEEN30024 Lecture 15
Biphase Manchester
and Differential Manchester
24
EEEN30024 Lecture 15
Block codes
25
EEEN30024 Lecture 15
4B/5B 0000
0001
11110
01001
Code a block of 4 bits 0010 10100
as a block of 5 bits 0011 10101
using NRZI 0100 01010
24 = 16 data blocks, 0101 01011
possible 25 = 32 code 0110 01110
blocks 0111 01111
Select 16 code blocks 1000 10010
with at least 2 1s 1001 10011
26
EEEN30024 Lecture 15
4B/5B-NRZI
27
EEEN30024 Lecture 15
28
EEEN30024 Lecture 15
4B3T Code
4B3T Code
31
EEEN30024 Lecture 15
Scrambling
Techniques
32
EEEN30024 Lecture 15
B8ZS
Based on bipolar-AMI
removes the case where there are long sequences of
zeros
33
EEEN30024 Lecture 15
HDB3
Based on bipolar-AMI
addresses the issues associated with runs of zeros
34
EEEN30024 Lecture 15
Appendix: (examinable)
Construction of Frames
A frame 'start' and 'end' must be marked
Character count
Flag bytes with byte stuffing
Starting and end flags with bit stuffing
Physical layer coding violations
35
EEEN30024 Lecture 15
Character Count
Include a field in the frame that contains the
number of characters to be found
37
EEEN30024 Lecture 15
Example Frame
ESC T E S T ESC
6 H E L L O
Frame 1
38
EEEN30024 Lecture 15
Flag Bytes with Byte Stuffing
Use a ‘special byte’ (a flag byte) to mark the
start and of frames
for example the byte 01111110 may be used
In binary data the flag byte may occur
prefix the flag byte in the data with a special escape byte
(ESC)
thus flag byte in data is two bytes ESC-FLAG
in binary data the ESC byte may occur, when it does
prefix with the ESC byte
thus ESC byte in data is given by ESC-ESC
The use of the ESC byte gives rise to the term ‘byte
stuffing’
Approach used in PPP (Point-to-Point Protocol)
39
EEEN30024 Lecture 15
Byte Stuffing
40
EEEN30024 Lecture 15
Bit Stuffing
A flag byte is used to mark the start and end of
frames as in byte stuffing
say the 01111110 we used earlier
41
EEEN30024 Lecture 15
42
EEEN30024 Lecture 15
Physical Layer Coding
Violations
Can use code violations or additional codes to
signal frame ends in physical coding systems that
use more than 1 signal bit
For example
Manchester coding requires a transition in the middle of
the data bit, a data bit with no transition could be used
to signal frame end
in 4B/5B coding there are 32 code, only 16 of which are
used to transmit data, other codes can be used to mark
frame boundaries
43
EEEN30024 Lecture 15
Lecture 16
Wireless Networks
Learning Outcomes :
IEEE 802.11
IEEE 802.15
references:
Reading: K&R Chapter 6
EEEN30024 Lecture 16 1
Elements of a
wireless network
network
infrastructure
EEEN30024 Lecture 16 2
Elements of a
wireless network
wireless hosts
laptop, smartphone
run applications
may be stationary
network (non-mobile) or mobile
infrastructure wireless does not
always mean mobility
EEEN30024 Lecture 16 3
Elements of a
wireless network
base station
typically connected to
wired network
relay - responsible for
sending packets
network between wired
infrastructure network and wireless
host(s) in its “area”
e.g., cell towers,
802.11 access points
EEEN30024 Lecture 16 4
Elements of a
wireless network
wireless link
typically used to connect
mobile(s) to base station
also used as backbone
link
network multiple access protocol
coordinates link access
infrastructure
various data rates,
transmission distance
EEEN30024 Lecture 16 5
Characteristics of
selected wireless links
200 802.11n
1 802.15
EEEN30024 Lecture 16 6
Elements of a
wireless network
infrastructure mode
base station connects
mobiles into wired
network
network provides the
network traditional services of
infrastructure addressing and
routing
EEEN30024 Lecture 16 7
Elements of a
wireless network
ad hoc mode
no base stations
nodes can only
transmit to other
nodes within link
coverage
nodes organize
themselves into a
network: route
among themselves
EEEN30024 Lecture 16 8
Wireless Network Taxonomy
no base station, no
connection to larger
no no base station, no Internet. May have to
connection to larger
infrastructure relay to reach other
Internet (Bluetooth, a given wireless node
ad hoc nets) MANET, VANET
EEEN30024 Lecture 16 9
Wireless
Link Characteristics (1)
important differences from wired link ….
EEEN30024 Lecture 16 10
Wireless
Link Characteristics (2)
SNR: signal-to-noise ratio 10-1
BER
10-4
given physical layer: increase
power -> increase SNR- 10-5
>decrease BER
10-6
given SNR: choose physical
layer that meets BER 10-7
requirement, giving highest 10 20 30 40
SNR(dB)
thruput
• SNR may change with QAM256 (8 Mbps)
mobility: dynamically adapt
physical layer (modulation QAM16 (4 Mbps)
technique, rate)
BPSK (1 Mbps)
EEEN30024 Lecture 16 11
Wireless
Network Characteristics
Multiple wireless senders and receivers create additional
problems (beyond multiple access):
A B C
C
EEEN30024 Lecture 16 12
Code Division Multiple Access
(CDMA)
all users share same frequency, but each user has own
“chipping” sequence (i.e., code) to encode data
allows multiple users to “coexist” and transmit
simultaneously with minimal interference (if codes are
“orthogonal”)
EEEN30024 Lecture 16 13
CDMA encode/decode
M
Di = Zi,m.cm
m=1
M
received 1 1 1 1 1 1 1 1
d0 = 1
-1 -1 -1 -1 -1 -1 -1 -1
input d1 = -1
1 1 1 1 1 1 1 1 slot 1 slot 0
code channel channel
-1 -1 -1 -1 -1 -1 -1 -1
EEEN30024 Lecture 16 14
CDMA:
two-sender interference
channel sums
together
transmissions by
Sender 1 sender 1 and 2
Sender 2
EEEN30024 Lecture 16 15
IEEE 802.11
Wireless LAN
802.11b 802.11a
2.4-5 GHz unlicensed spectrum 5-6 GHz range
up to 11 Mbps up to 54 Mbps
direct sequence spread 802.11g
spectrum (DSSS) in physical 2.4-5 GHz range
layer up to 54 Mbps
all hosts use same chipping 802.11n: multiple antennae
code 2.4-5 GHz range
up to 200 Mbps
EEEN30024 Lecture 16 16
802.11
LAN Architecture
wireless host
communicates with base
Internet station
base station = access
point (AP)
Basic Service Set (BSS)
hub, switch (aka “cell”) in
or router infrastructure mode
contains:
wireless hosts
access point (AP): base
BSS 1
station
ad hoc mode: hosts only
BSS 2
EEEN30024 Lecture 16 17
802.11:
Channels, Association
EEEN30024 Lecture 16 18
802.11:
Passive/Active Scanning
BSS 1 BSS 2 BSS 1 BSS 2
1
1 1 2 2 AP 2
AP 1 AP 2 AP 1
2 3
3 4
H1 H1
IEEE 802.11:
Multiple Access
avoid collisions: 2+ nodes transmitting at same time
802.11: CSMA - sense before transmitting
don’t collide with ongoing transmission by other node
802.11: no collision detection!
difficult to receive (sense collisions) when transmitting due to
weak received signals (fading)
can’t sense all collisions in any case: hidden terminal, fading
goal: avoid collisions: CSMA/C(ollision)A(voidance)
A B C
C
space
EEEN30024 Lecture 16 20
IEEE 802.11 MAC Protocol:
CSMA/CA
802.11 sender
1 if sense channel idle for DIFS then sender receiver
transmit entire frame (no CD)
2 if sense channel busy then DIFS
start random backoff time
timer counts down while channel idle
data
transmit when timer expires
if no ACK, increase random backoff interval,
repeat 2 SIFS
EEEN30024 Lecture 16 21
EEEN30024 Lecture 16 22
Collision Avoidance: RTS-CTS exchange
A B
AP
SIFS
SIFS
DATA (A)
B
defers
time SIFS
EEEN30024 Lecture 16 23
2 2 6 6 6 2 6 0 - 2312 4
frame address address address seq address
duration payload CRC
control 1 2 3 control 4
Address 4: used
only in ad hoc mode
Address 1: MAC address
of wireless host or AP Address 3: MAC address
to receive this frame of router interface to which
AP is attached
Address 2: MAC address
of wireless host or AP
transmitting this frame
EEEN30024 Lecture 16 24
802.11 Frame: addressing
Internet
H1 R1 router
802.3 frame
802.11 frame
EEEN30024 Lecture 16 25
2 2 6 6 6 2 6 0 - 2312 4
frame address address address seq address
duration payload CRC
control 1 2 3 control 4
2 2 4 1 1 1 1 1 1 1 1
Protocol To From More Power More
Type Subtype Retry WEP Rsvd
version AP AP frag mgt data
frame type
(RTS, CTS, ACK, data)
EEEN30024 Lecture 16 26
802.11:
Mobility Within Same Subnet
H1 remains in same IP
subnet: IP address can
remain same
switch: which AP is
associated with H1?
self-learning: switch
will see frame from H1
and “remember” which
switch port can be used BSS 1 H1 BSS 2
to reach H1
EEEN30024 Lecture 16 27
802.11:
Advanced Capabilities
Rate adaptation
10-1
10-2
base station, mobile 10-3
dynamically change
BER
10-4
transmission rate (physical
layer modulation 10-5
EEEN30024 Lecture 16 28
802.11:
Advanced Capabilities
power management
EEEN30024 Lecture 16 29
802.15:
Personal Area Network
master/slaves: P
S S
slaves request permission to P
send (to master)
master grants requests
802.15: evolved from
M Master device
Bluetooth specification
2.4-2.5 GHz radio band S Slave device
up to 721 kbps P Parked device (inactive)
EEEN30024 Lecture 16 30
Chapter 6 summary
Wireless
wireless links:
capacity, distance
channel impairments
CDMA
IEEE 802.15
Personal Area Networks
EEEN30024 Lecture 16 31
Appendix: (examinable)
MAC – Coordination function
This is the mechanism that controls access to the wireless
medium within a BSS
Ethernet would use CSMA/CD for this purpose
EEEN30024 Lecture 16 32
IEEE 802.11 MAC Coordination
2 Modes
DCF (Distributed Coordination Function)
Basic operation has been described earlier
CTS-RTS
Distributed in the sense that all stations take part
like Ethernet
PCF (Point Coordination Function)
Managed by Access Point (Base Station) for BSS
(cell)
Contention-free system based on polling
Built on top of DCF
DCF and PCF can work together
PCF for time critical services
EEEN30024 Lecture 16 33
DCF at non-participating
stations
EEEN30024 Lecture 16 34
DCF Issues (1)
EEEN30024 Lecture 16 35
EEEN30024 Lecture 16 36
Errors
Wireless networks are more prone to error at the
physical level than a wired network.
EEEN30024 Lecture 16 37
Errors
EEEN30024 Lecture 16 38
Reducing retransmissions
due to bit errors
If a frame is split into smaller fragments
each one being separately acknowledged.
The number of retransmissions is reduced at the
expense of additional bandwidth requirements to
transmit the acknowledgements
Each fragment has its own checksum
each fragment has a sequence number
a stop and wait protocol is used – i.e. wait for
acknowledgement.
There also has to be a mechanism to ensure that
other stations do not collide with the transmissions
This is handled by the way in which the Interframe
Spacing is specified – see later.
The mechanism allows repeated fragments to be sent
without an new RTS/CTS handshake taking place.
EEEN30024 Lecture 16 39
Reducing retransmissions
due to bit errors - example
EEEN30024 Lecture 16 40
PCF
This is a contention-free algorithm managed
by a base station (access point)
The base station periodically sends a Beacon
Frame (10 to 100 times per second)
this broadcasts various system parameters
allows stations to sign up for the PCF service.
The base station will periodically poll stations
signed up for the service and accept their
frames.
The algorithm supports stations that have
time-critical requirements.
It can cause stations to sleep – thus saving
power.
PCF can coexist with DCF.
EEEN30024 Lecture 16 41
Interframe Spaces
EEEN30024 Lecture 16 42
Interframe Spacing
EEEN30024 Lecture 16 43
Interframe Spacing
EEEN30024 Lecture 16 44
Interframe Spacing
PIFS - Point coordination Interframe Spacing
A beacon frame or the polling of a station by the
base station.
Has higher priority than contention-based traffic.
Polling needs to organised so that it does not freeze
out the contention-based traffic
• a 'Superframe' is used with all polling taking place
at the beginning of the 'Superframe'.
DIFS – DCF Interframe Spacing
RTS, operated under the DCF algorithm given earlier
uses exponential backoff in the face of collisions.
EIFS – Extended Interframe Spacing
reports bad or unknown frames.
EEEN30024 Lecture 16 45
Lecture 17:
Network Security 1
Introduction
Symmetric Key Encryption
Learning Outcomes :
Be able to
Identify and explain the key network security
requirements, principles and assumptions
Explain symmetric-key encoding algorithms
1
EEEN30024 - Data Networking - Lecture 17
Network Security
Requirements
Confidentiality (Secrecy)
keep information out of the hands of unauthorised 3rd
parties
Integrity
ensure that data is not modified by unauthorised 3rd
parties
Authenticity
Ensure the identify of a party
they actually are who they say they are
Non-repudiation
ensure that having sent a message the sender cannot
subsequently deny having sent it
2
EEEN30024 - Data Networking - Lecture 17
Confidentiality
with Encryption
In both cases,
3
EEEN30024 - Data Networking - Lecture 17
Types of attack
4
EEEN30024 - Data Networking - Lecture 17
Principles and Assumptions (1)
Algorithm is known to the attacker, only the key
is secret
principle first stated by Kerckhoffs
-assume the encryption system is secure even if it
knowledge of how it works is available
5
EEEN30024 - Data Networking - Lecture 17
6
EEEN30024 - Data Networking - Lecture 17
Cryptosystems and keys
There are two fundamental types of
cryptographic key encryption/decryption
systems.
Those that use a shared secret key –based on the use of
‘symmetric key’ algorithms.
Those that avoid the sharing of secret keys –based on
the use of ‘asymmetric key’ algorithms.
Some protocols either use one or the other of these
types, for example computer login account verification.
7
EEEN30024 - Data Networking - Lecture 17
Symmetric-key
Algorithms
Use the same key for encryption and decryption
Alice and Bob must have the same key
8
EEEN30024 - Data Networking - Lecture 17
Basic Tools: XOR with Key
9
EEEN30024 - Data Networking - Lecture 17
K (P K) = 01110001
00101101
01011100 – recovered by Bob
10
EEEN30024 - Data Networking - Lecture 17
Basic Tools: Bit Scrambling
11
EEEN30024 - Data Networking - Lecture 17
Symmetric–Key Algorithms
with XOR and bit scrambling
To provide a complex encoding several rounds
are used
13
EEEN30024 - Data Networking - Lecture 17
14
EEEN30024 - Data Networking - Lecture 17
DES Stages [2]
15
EEEN30024 - Data Networking - Lecture 17
Rounds
16
EEEN30024 - Data Networking - Lecture 17
Round
17
EEEN30024 - Data Networking - Lecture 17
DES
DES has a 56-bit key (for political reasons)
DES has been broken
the key can be found within one day – 7.2x1016 keys
DES is relatively quick
Triple DES is used, this applies the algorithm three
times
can use two keys
112 bits believed to be adequate – 5.2x1033 keys
if K1 = K2, compatible with single DES
can use 3 keys (168 bits – 3.7 x 1050)
18
EEEN30024 - Data Networking - Lecture 17
Advanced Encryption Standard
(AES)
19
EEEN30024 - Data Networking - Lecture 17
AES Algorithm
Ciphertext
20
EEEN30024 - Data Networking - Lecture 17
AES Algorithm
21
EEEN30024 - Data Networking - Lecture 17
AES Algorithm
The initial step is to XOR RK0 with the state
before the rounds start
22
EEEN30024 - Data Networking - Lecture 17
AES Algorithm
23
EEEN30024 - Data Networking - Lecture 17
Symmetric-Key
Algorithms
In effect, a symmetric key algorithm simply substitutes one
block of plaintext for another block of ciphertext.
24
EEEN30024 - Data Networking - Lecture 17
Cipher Block Chaining
The idea is to XOR each plaintext block with the
preceding ciphertext block before it is encrypted.
25
EEEN30024 - Data Networking - Lecture 17
26
EEEN30024 - Data Networking - Lecture 17
Symmetric-Key Algorithms
Asymmetric-Key Algorithms
27
EEEN30024 - Data Networking - Lecture 17
Lecture 18:
Network Security 2
Asymmetric Key Encryption
Digital Signatures
Learning Outcomes :
Be able to
Explain and use the RSA algorithm with small values of n
Explain how digital signatures are used
Identify the ways in which digital signatures can be created
and how they protect data
Describe the methods by which message digests can be
used to provide digital signatures
Explain how the ‘birthday attack’ can be used to generate 2
messages with the same one-way hash function result
references:
Kurose and Ross chapter 8
Asymmetric-Key Algorithms
Considered from Alice’s perspective she has two
keys
EA, which is her public key used by people who wish to
communicate with her to encode plaintext
DA, which is her private key which she uses on the cipher
text to decipher a message encoded with EA
Thus
P = DA(EA(P))
determining DA from EA must be very difficult, since EA is
public
the ciphertext cannot be decrypted
Eve can have access to the encryption algorithm and
Alice’s public key
It is very secure
RSA approach
- preliminaries
Two large prime numbers (p and q) are chosen
large = 512 bits
Calculate
n = p x q and z = (p - 1) x (q – 1)
RSA
RSA may not seem that secure
if z and e are known the attacker can use Euclid’s algorithm
to get d
since e is known (part of public key) the attacker needs
only z
Digital Signatures
Verification of sender
Alice sent the message (not Trudy)
Message cannot be repudiated
Alice cannot deny that she sent the message
Message cannot be altered nor concocted
Bob/Trudy cannot construct the message and pretend
Alice sent it
Look at 3 techniques
Symmetric-key cryptography with a Trusted Central
Agency
Asymmetric-key cryptography
Message Digests with asymmetric-key cryptography for
signing
Symmetric-key
cryptography with a Trusted
Central Agency
CTA must be trusted, if so
Verification of sender
CTA can verify Alice because of the use of her key, Bob
trusts CTA to say it’s Alice and CTA does so in a message
encrypted with Bob’s key
Message cannot be repudiated
Bob keeps KCTA(A, t, P), which can be verified by CTA if
dispute arises
Message cannot be altered nor concocted
Bob cannot create KCTA(A, t, P)
Trudy cannot encode the CTA’s message to Bob because
she does not know KB
DA(P)
Asymmetric-key
cryptography
Verification of sender
Message encrypted using Alice’s private key (DA), must
be Alice
Message cannot be repudiated
Message encrypted using Alice’s private key (DA), must
be Alice
Message cannot be altered nor concocted
Message encrypted using Alice’s private key (DA),
Bob/Trudy cannot fake this
17
EEEN30024 - Data Networking - Lecture 18
Message Digest
Properties
H can be applied to a block of data of any size
H produces a fixed-length digest
Given P, H(P) is easy to compute
Given H(P) it is impossible to find P
Not necessary for all implementations
Message digests
and authorship
De-
En-
Message Digests
and the Birthday Attack
n possible inputs with m possible outputs
There are possible input pairs
Message Digests
and the Birthday Attack
Learning Outcomes
Be able to
Explain Public Key Infrastructure (PKI).
Explain various Authentication Protocols and
state how they are vulnerable to attack.
Explain how key exchange protocols function and
be able to calculate the key from n, g, x and y
using the Diffie-Hellman key exchange.
Two-way Authentication
Shared Secret Key
Requires that key be established a priori.
The 3-step protocol can be defeated by a
reflection attack by Trudy (next slide)
This is easier if Bob can have multiple concurrent
sessions.
The 5-stage protocol also has vulnerabilities
If Alice is a general purpose computer with which
Trudy can open sessions, Trudy can mount a
reflection attack
not considered in this lecture
Two-way Authentication
Shared Secret Key – Reflection Attack
General rules for addressing the issue:
Make the initiator prove his/her identity before the
responder does
Bob gives his identity before Trudy has supplied any
useful information.
Use a pair of shared keys – one for initiator and
one for responder.
Use nonces from different sets
e.g. Even for initiator, odd for responder
Ensure that information from one concurrent
session cannot be usefully used in another.
Using HMAC
A = Alice’s Identity
B = Bob’s Identity 1. A, RA
K = Shared Key 2. RB, HMAC(RA, RB, A, B, K)
R = Random Alice Bob
Number or nonce 3. HMAC(RA, RB, K)
n = 23, g = 5
Alice x = 6
Bob y = 15
Alice sends 23, 5, 56 mod 23 (=8)
Bob sends 515 mod 23 (=19)
Key is 5(6x15) mod 23 = 2
Alice by 196 mod 23 = 2
Bob by 815 mod 23 = 2
Trudy can establish secret keys with both Bob and Alice
provided she can intercept all messages
Thus the key exchange is vulnerable
Moreover, it is not efficient in the long term as a private key is
needed for each communication partner
1. Alice informs the KDC she wishes to establish a session with Bob.
2. KDC replies with a message encrypted using Alice’s key containing
Alice’s challenge, Bob’s identity, a session key and a coded using
Bob’s key with Alice’s identity and the session key.
3. Alice passes the message from the KDC to Bob and encodes a
challenge using the session key.
4. Bob responds to the challenge with a value one less than the
nonce RA2 and, to prevent a replay by an intruder from Step 3, Bob
issues his own challenge.
5. Alice responds to the challenge with a value one less than RB,
again to nullify interception of Step 4.
EEEN30024 - Data Networking - Lecture 19 25
t = time
Using Kerberos
Alice types her name at a workstation it is sent to AS.
AS responds with a session key (KS) and an
encrypted message for the TGS containing Alice’s
identity and the session key.
The workstation now asks for Alice’s password, the
password generates KA so the AS’s message can be
decrypted, Alice’s password can now be deleted by
the workstation.
Alice then sends a message to the TGS consisting of
the encrypted message she received from the AS
together with Bob’s identity and the timestamp (t)
encrypted using the session key.
Using Kerberos
If Alice wishes to start a session with another server,
she simply sends a message to the TGS in the form
of Step 3, but with the identity of the new server
instead of Bob.
ASs and TGSs are distributed into multiple realms
To communicate with a server in another realm Alice
asks her TGS for a ticket that will be recognised by
a TGS in the other realm.
TGSs therefore need to register with TGSs in
remote realms
in the same way as servers must be registered with their
local TGS.