Professional Documents
Culture Documents
Textbook Ch2 - 3
Instructor: Munehiro Fukuda
These slides were compiled from the course textbook, the reference books, and
the instructors original materials.
Winter, 2004
OSI 7 Layers
Site
A
7
Application
Presentation
Session
Transport
Network
Data link
Physical
Site
B
Application protocol
Presentation protocol
Session protocol
Transport protocol
Network protocol
Data link protocol
Physical protocol
Application
Presentation
Session
Transport
UDP, TCP
Network
IP
Data link
IEEE802.2
connection or connectionle
Ethernet
Physical
Network
Winter, 2004
1 listen
3. detect
2 transmit
1. Free token
2. Attach
3. busy token
Winter, 2004
4. Detach
Network Layer
Example: IP
Transportation layer
Datagram
Class A
fragmentation
SDL
reassembly
SDL
IP packet ID and size
Destination IP address
Source IP address
0 Net #
Octet 1
0-127
Host #
Octet 2 4
(1,677,716)
Class B
Host #
Octet 3 4
(65,536)
Class C
110
Octet 1
128-191
Net #
Host#
Octet 2 3
Octet 4
(256)
Winter, 2004
Transport Layer:
Example1: UDP
client
socket()
bind()
sendto()
recvfrom()
Winter, 2004
server
sendto()
Transport Layer:
Example2: TCP
client
server
write()
read()
read()
wrte()
Winter, 2004
Application Layer
Example: RSH
Client
Server
shell
TCP connection
request
Command
rsh ls- l
inetd
rshd
TCP connection
Inherited all the way
To a child
shell
Command
ls -l
Winter, 2004
Socket Programming:
Socket.h
#include <iostream>
extern "C"
{
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
}
// for sockets
// for gethostbyname( )
// for close( )
// for bzero( )
#define NULL_FD -1
#define MAXSIZE 20
class Socket {
public:
Socket( int );
~Socket( );
int getClientSocket( char[] );
int getServerSocket( );
private:
int port;
int clientFd;
int serverFd;
};
Winter, 2004
Socket Programming:
Socket.cpp (Client)
// Fill in the structure "sendSockAddr" with the server address.
sockaddr_in sendSockAddr;
bzero( (char*)&sendSockAddr, sizeof( sendSockAddr ) );
sendSockAddr.sin_family
= AF_INET; //Address Family Internet
sendSockAddr.sin_addr.s_addr =
inet_addr( inet_ntoa( *(struct in_addr*)*host->h_addr_list ) );
sendSockAddr.sin_port
= htons( port );
#include "Socket.h"
Socket::Socket( int port )
: port( port ), clientFd( NULL_FD ),
serverFd( NULL_FD ) {
}
Socket::~Socket( ) {
if ( clientFd != NULL_FD )
close( clientFd );
if ( serverFd != NULL_FD )
close( serverFd );
}
Winter, 2004
Socket Programming:
Socket.cpp (Server)
int Socket::getServerSocket( ) {
if ( serverFd == NULL_FD ) { // Server not ready
sockaddr_in acceptSockAddr;
listen( serverFd, 5 );
if( ( newFd =
accept( serverFd, (sockaddr*)&newSockAddr, &newSockAddrSize ) ) < 0 ) {
cerr << "Cannot accept from another host." << endl;
return NULL_FD;
}
return newFd;
Winter, 2004
10
}
Winter,
2004
11
Blocking/Non-Blocking
Communication
Blocking communication
Rendezvous
Non-blocking communication
Winter, 2004
12
Polling
Example:
set_fl(sd, O_NONBLOCK);
// set the socket as non-blocking
pfd.fd = sd;
Example:
signal(SIGIO, sigio_func);
// set a future interrupt to call
sigio_func( )
Winter, 2004
13
Buffering
message
message
message
message
message
message
Winter, 2004
No Buffering
Rendezvous
Performance drawback
Single Message Buffer
Stop-and-wait protocol
Unsuccessful communication
- GoBack-N Technique
Flow-controlled communication
sliding window in TCP
14
Process Addressing
Explicit address
machine id + local id
Example: TCP/IP and UDP/IP use IP + port
Winter, 2004
15
Failure Handling
client
ack
server
client
server
request
request
timeout
request 2
response
response
response 2
request
timeout
request
ack
response
ack
timeout
Winter, 2004
request 2
Loss of request
message
Loss of response
message
Unsuccessful
execution of
request
Do we really need
acknowledgment
messages?
16
Idempotency
client
server
request
server
client
request
Timeout
request 2
response
Timeout
request 3
Timeout
response
request 4
reesponse 2
Winter, 2004
17
Exactly-One Semantics
Withdraw $100
Withdraw995 $100
$1000-$100
= $900
Not received
Withdraw $100
$1000-$100
Not received
Withdraw995 $100
Trans995 completed
No subtraction
$900-$100
=$800!
$100 received
$100 received
Winter, 2004
What if errors
in the banking
system
New semantics
required:
Exactly-one
semantics
Server must
keep track of
the request
sequence
18
3.
4.
5.
Winter, 2004
19