Vous êtes sur la page 1sur 44

Chapter 3: Network and Communication

 What is a network?
 What types of network are there?
 What networking standards are there?
 How do you represent information?
 What is communication protocol?
 What are communication models? (message-
passing, stream communication and RPC)
Distributed Systems 1
Anatomy of a network
 A set of interconnected
resources
 Hosts that run network
applications software
 Clients and servers
 Set of peers
 The network infrastructure that
interconnects the hosts
 The networking hardware
and software
 Network node devices

such as routers and


switches
 Links: cables,

connectors, network
interfaces
Distributed Systems 2
Transmission links
 Convey bits, bytes, packets
 Physical medium
 Copper (or aluminium)
 Optical fibre
 Glass, plastic

 Free-space optical
 Laser

 Radio
 Satellite, microwave link, mobile, wireless LAN,

‘Bluetooth’
 Mode
 Point-to-point
 Shared medium (multicast)
 Broadcast
Distributed Systems 3
Representing data: bits and bytes

 Bits
 Different codes used in different interface standards
 Images, multi-media
 Require special bit pattern as delimiter
 Bytes
 Text is usually ASCII or Unicode characters
 Text files, documents
 Character set includes special control characters

Bits Bytes

01100001011000111 01110101 00000010 10000000 10100001


Distributed Systems 4
Representing data: Frames

 A block of data is called a frame


 Basic unit of transfer between switches
 Main purpose of frame is to carry packets from one point to another on a
network
 Header carries
 Addressing (usually rather low level)

 Control information for receiving network device (host/network

node)
 Trailer (if present) carries error check
 Used for detecting errors in received frame

 Block sizes restricted by buffer sizes in the network device interfaces

Frame: header Data or payload trailer


Distributed Systems 5
Representing data: Packets

 Blocks of application data with some networking routing information


 Basic unit of transfer between routers
 Header carries
 Network-wide addressing information
 Control information for receiving network device (host, router)
 No information is appended to a packet
 There is no trailer, as there is with frames
 In theory, packets can be quite large

Packet: header Data or payload

Distributed Systems 6
Types of network

 Main types:
 LAN, WAN, MAN, and Internet
 LAN (Local Area Network) is mainly private
 Ether net, Token ring
 Or interconnected
 WAN (Wide Area Network) can be private or public
 Interconnected
 MAN (Metropolitan Area Network) is mainly public
 Interconnected by Optical fibre
 Global Network is public
 The internet
 The telephone network

Distributed Systems 7
Interconnecting LANs and WANs

 Host systems usually connect into a


LAN switch
– Number of hosts limited by the
switch
number of ports on the switch
 Routers have two main uses
 Interconnecting LANs
 Connecting to a WAN or to the
router
Internet To the
Internet
 Routers interconnect LANs
 To separate the users
 To separate the traffic To offsite
LANs

Distributed Systems 8
OSI: The International Standards Model

 Created in the 1980s by the standards bodies


 ISO, ITU-T(Telecommunication Standardization Sector) , IEEE
 Contributors included people from all sectors of the industry,
government and academia
 Designed originally to overcome the problems of non-interoperability
between different manufacturers’ computers
 Is a protocol suite
 A set of interdependent layer functions
 A set of interdependent protocols
 Ten years of development rendered it too complex to be of real
practical use, however, we still use
 Most of the Layer names
 Some of the terminology

Distributed Systems 9
OSI: A Seven Layer Protocol

high level application


Layer 7- Application
support tools
conversion between different application
Layer 6 - Presentation machine representations protocols
applications synchronization and
Layer 5 - Session connection management
last chance to correct network
Layer 4 - Transport errors before passing to application

Layer 3 - Network network addressing & routing


networking
link control & protocols
Layer 2 - Link: data transmission

Layer 1 - Physical physical medium control,


bit transmission & timing

Distributed Systems 10
The OSI and IETF Protocol Suites

IETF: The Internet Engineering Task Force


OSI: Open System Interconnection Reference Model

IETF model OSI model

Layer 7- Application

application
layers 5/6/7: Layer 6 - Presentation protocols
Application
Layer 5 - Session

TCP, UDP Layer 4 - Transport

IP Layer 3 - Network networking


protocols
Logical
PPP, 802.3,5,11, etc Layer 2 - Link:
MAC

Physical Layer 1 - Physical

Distributed Systems 11
Protocol Data Encapsulation

Application Application data


Layer

Transport T hdr App data Transport header and


Layer payload (e.g. TCP segment)

Network N hdr Transport Network header and


Layer payload (e.g. IP packet)

Link Layer L hdr Network CRC


Link header and payload
(e.g. Ethernet frame)
Physical Layer

101011100101

Distributed Systems 12
A Typical Message on the Network

Distributed Systems 13
Protocol Data Flow

Addresses Addresses

Web DNS URL


client client Web server
Source port Destination port
TCP UDP TCP UDP
Transport protocol Transport protocol
IP IP
Source IP Destination IP
Encapsulation Encapsulation
Source NIC
Physical network Physical network Destination NIC

Distributed Systems 14
Communication Models

• Message Passing
lowest level of communication, e.g. sockets
unstructured peer-peer IPC
varieties of communication patterns
• Data Stream
continuous media
satisfy real time data services
• Request / Reply semantics
basis of Client-Server
RPC (Remote Procedure Call)
RMI (Remote Method Invocation)

Distributed Systems 15
Message Passing Definitions(1)
 Procedures: send, receive, accept, create, connect, locate , re
ply, acknowledge
 Multiplicity: point-to-point, broadcast, multicast
 Message Content: data or instruction, by value or by reference (addre
ss)
 Channels:
 - link, port, mailbox
 - direction can be uni-diection or bi-direction
 - capacity can be unbounded (i.e. asynchronous, no blocking)
 or null (implies synchronous) or fixed (implies buffering)
 Message Receipt:
 explicit receive – receiver can select message
 implicit receive – receiver must receive from sender

Distributed Systems 16
Message Passing Definitions(2)
 Synchronous/Asynchronous
 Synchronous – receiver waits ready for sender message and responds in
real time (e.g. phone call). Both sender and receiver return when transfer i
s complete. No buffer is required.
 Asynchronous – sender sends message into buffer, message picked
up later at receivers convenience (e.g. mailbox). Sender process retur
ns whether or not a message is received. Receiver blocks until the me
ssage is available
 Blocking/Non-Blocking
 Blocking – sender cannot proceed after sending message until receiver pi
cks up message
 Non Blocking – sender can continue as soon as message send is done
(e.g. added to buffer)
 Sender/Receiver Naming
 Static – sender and receiver names (location) fixed
 Dynamic – names may change (e.g. ask a static name server

Distributed Systems 17
Message Passing Definitions(3)
 Connection Link
 Connection Oriented – link is established and held for duration of
service. Guaranteed link but bandwidth may be wasted.
 Connectionless – connection not established until message send
occurs e.g. different packets sent by different routes
 Transient
 message is only stored by system while sender and receiver are ex
ecuting (e.g. MSN messenger)
 Persistent
 message is stored and delivered by system, even if receiver is not
executing (e.g. email)

Distributed Systems 18
Persistence and Synchronicity in Communication (1)

General organization of a communication system in


which hosts are connected through a network

Distributed Systems 19
Persistence and Synchronicity in Communication (2)

(a) Persistent asynchronous communication


(b) Persistent synchronous communication

Distributed Systems 20
Persistence and Synchronicity in Communication (3)

(c) Transient asynchronous communication


(d) Receipt-based transient synchronous communication

Distributed Systems 21
Persistence and Synchronicity in Communication (4)

(e) Delivery-based transient synchronous communication


at message delivery
(f) Response-based transient synchronous communication

Distributed Systems 22
Socket Programming

• A socket is a communication endpoint between processes


• A socket forms the API that allows processes to communicate
point-to-point over the internet, within a LAN or within a single
computer
• Each internet host implements the TCP/IP family of protocols
• A socket is identified by a socket address consisting of an IP
(version 4) address and port number e.g. 129.86.5.20:80
• IP addresses are stored as unsigned 32 bit integer, and frequently
represented in dotted decimal notation.
/* Internet address structure */
struct in_addr {unsigned int s_addr;};
• Port numbers are unsigned 16 bit integers (range 0-65535). Port
numbers 0-1024 are well known and reserved, e.g. 21 ftp, 23 telnet,
25 email, 80 http...

Distributed Systems 23
Socket Families and Types
• AF_UNIX – for communicating between processes on the same
(UNIX) computer.

• AF_INET – for communicating between processes on different


machines connected by the internet or a LAN.

•SOCK_STREAM is for reliable TCP (Transmission Control Protocol)


connection oriented communication that can be for AF_UNIX or
AF_INET sockets. These streaming sockets allow for continuous
communication.

• SOCK_DGRAM is for unreliable UDP (User Datagram Protocol)


connectionless communication in which process are not required to
connect to the socket continuously. These datagram sockets allow
data to be sent in finite packets (or datagrams). The datagram
protocol applies only to internet AF_INET sockets.

Distributed Systems 24
Socket primitives for TCP/IP

Primitive Meaning

Socket Create a new communication endpoint

Bind Attach a local address to a socket


Announce willingness to accept
Listen
connections
Block caller until a connection request
Accept
arrives
Connect Actively attempt to establish a connection

Send Send some data over the connection

Receive Receive some data over the connection

Close Release the connection

Distributed Systems 25
TCP/IP Socket Calls for Connection

socket() create socket

bind() bind local IP address of socket to port

listen() place socket in passive mode ready


to accept requests
accept() take next request from queue (or wait) then forks
and create new socket for client connection
socket()
Blocks until
connection connect() Issue connection request to server
from client

recv() send()
Process request Transfer message strings with
send/recv or read/write
send() recv()

close() close() Close socket

Server Client

Distributed Systems 26
UDP/IP Socket Calls for Connection

socket() create socket

bind() bind local IP address of socket to port

recvfrom() Receive senders address


and senders datagram

blocks until
datagram socket()
received
from a client
request specify senders address
sendto()
and send datagram
Process request
reply
sendto() recvfrom()

close() Close socket

Server Client

Distributed Systems 27
UDP/IP Socket program example(1)

#include <stdio.h> juliet_addr.sin_family = AF_INET;


#include <sys/types.h> juliet_addr.sin_addr.s_addr = inet_addr(“xxx.xxx.x
#include <sys/socket.h> xx.xxx”);
#include <netinet/in.h> juliet_addr.sin_port = PORT_NUM;

#define PORT_NUM 2222 strcpy(message, “Juliet, I love you!”);


char message[20];
sendto(romeo, message, sizeof(message), 0,
main(){ /* process : Romeo.c */ (struct sockaddr) &juliet_addr, sizeof(juliet_addr));
int romeo,fromlen;
struct sockaddr_in romeo_addr, juliet_addr; fromlen = sizeof(juliet_addr);

romeo = socket(AF_INET, SOCK_DGRAM, 0); recvfrom(romeo, message, sizeof(message), 0,


romeo_addr.sin_family = AF_INET; (struct sockaddr) &juliet_addr, &fromlen);
romeo_addr.sin_addr.s_addr = INADDR_ANY;
romeo_addr.sin_port = 0; printf(“Juliet says: %s\n”, message);

bind(romeo, (struct sockaddr*)&romeo_addr, si close(romeo);


zeof(romeo_addr)); }

Distributed Systems 28
UDP/IP Socket program example(2)

#include <stdio.h>
#include <sys/types.h> fromlen = sizeof(juliet_addr);
#include <sys/socket.h>
#include <netinet/in.h> recvfrom(juliet, message, sizeof(message), 0,
(struct sockaddr) &romeo_addr, &fromlen);
#define PORT_NUM 2222
char message[20]; printf(“Romeo says: %s\n”, message);

main(){ /* process: Juliet.c */ strcpy(message, “Oh, Romeo! I love you too!”);

int juliet,fromlen; sendto(juliet, message, sizeof(message), 0,


struct sockaddr_in romeo_addr, juliet_addr; (struct sockaddr) &romeo_addr, sizeof(romeo_ad
dr));
juliet = socket(AF_INET, SOCK_DGRAM, 0);
juliet_addr.sin_family = AF_INET; close(juliet);
juliet_addr.sin_addr.s_addr = INADDR_ANY; }
juliet_addr.sin_port = PORT_NUM;

bind(juliet, (struct sockaddr*)&juliet_addr, sizeo


f(juliet_addr));

Distributed Systems 29
Stream Oriented Communication

sender receiver

 Continuous Media: the temporal relationships between different


data item are fundamental to correctly interpreting what the data
actually means (movies, audio streams).
 Discrete Media: the temporal relationships between data items are
not important (text, still images).

Distributed Systems 30
Data Stream transmission modes

 Asynchronous mode: no timing constraints on data stream.


 Synchronous mode: there is a max end-to-end delay, but how about
too fast?
 Isochronous mode: data items are transferred on time, both max
delay and min delay.

Distributed Systems 31
Specifying QoS

Characteristics of the Input Service Required

 maximum data unit size (bytes)  Loss sensitivity (bytes)


 Token bucket rate (bytes/sec)  Loss interval (sec)
 Toke bucket size (bytes)  Burst loss sensitivity (data units)
 Maximum transmission rate  Minimum delay noticed (sec)
(bytes/sec)  Maximum delay variation (sec)
 Quality of guarantee

 QoS(Quality of Service): a set of requirements describing what is


needed from the underlying distributed system and network to ensure
the temporal relationships, transmission rates, reliability, etc.

Distributed Systems 32
Token bucket algorithm

 Tokens are generated at a constant rate, and a token represents a fixed


number of bytes, say k.
 Tokens are buffered in a bucket.
 When an application wants to pass N bytes, it will take N/k tokens
from the bucket.

Distributed Systems 33
Request / Reply Model

Principle of RPC between a client and server program.

Distributed Systems 34
Local Procedure Call
main(){
char cip[] = “Buubdl!bu!ebxo”; /* cipher*/
int key = 1;/* secret key */ call
int len = decrypt(cip, key); /* LPC */
/* other processing */ LPC
} procedure
int decrypt(char * s, int key){ /* decryption */
int i = 0;
while( *s) { *s -= key; i++; s++;} return
return i;
}

stack stack stack

Return address
i -> 0
s -> main.cip
before key -> 1 after
cip ->Buubdl!bu!ebxo cip ->Buubdl!bu!ebxo cip ->Attack at dawn
len -> ? len -> ? len -> 14
key -> 1 key -> 1 key -> 1

Distributed Systems 35
Remote Procedure Call
Binding server

binder
(0)
recv req
program stub (2) register stub procedure
or search
return
LPC Bind req recv req execute
(1) (3) (5) (5)
(1) Recv bind unmarsh
marshal (4)
Send req LPC

Recv resu marshal


lt (6)
(8) send
(8) unmarsh (7) result
(6) return
return

client server

Distributed Systems 36
Remote Procedure Call: steps
(0) Remote procedures registration;
(1) Client procedure calls client stub in normal way;
(2) Client stub sends a binding request asking for information;
(3) Binding server searches for binding and reply to client stub;
(4) Client stub packs a message (marshalling) and send to server stub;
(5) Server stub unpacks parameters (unmarshalling), invokes LPC;
(6) Server procedure executes and returns results to server stub;
(7) Server stub packs results (marshalling) and sends to client stub;
(8) Client stub unpacks results and returns to client procedure.

Call-by-value: parameter is a straight value (int, float, …)


Call-by-reference: parameter is a pointer to anything (int,
record, array, pointer, …)
Distributed Systems 37
Example: SUN RPC (1)

/* eXtended Data Representation (XDR) definition , file name : caesar.x */

const MAX = 100;

typedef struct { /* return type */


int len;
char code[MAX];
} Data;

typedef struct { /* parameter type */


int key;
char cipher[MAX];
} Args;

program CAESAR { /* CAESAR program */


version VERSION {
Data DECRYPT(Args) = 1; /* decryption procedure */
Data ENCRYPT(Args) = 2; /* encryption procedure*/
} = 5;
} = 8888;

Distributed Systems 38
Example: SUN RPC(2)

Invoke XDR compiler rpcgen to generate the


following files:
 Client stub
 Server main program and server stub
 XDR parameter marshalling/unmarshalling functions
 Program header file, caesar.h, which includes constants,
user defined types, remote procedure prototypes.

Now, we are ready to design other programs.

Distributed Systems 39
Example: SUN RPC(3)

/* client program file : client.c */ /* server program file : server.c */

#include <rpc/rpc.h> #include <rpc/rpc.h>


#include “caesar.h” #include “ceasar.h”

main(){ Data* decrypt_2(Args *a){ /* decryption */


CLIENT *cp; static Data output; /* must be static */
char *serverName = “Caesar_server”; char s = a->cipher;
Args arg; int i = 0;
Data * plaintext; while( *s) { output.code[i] = *s - key; i++; s++;}
/* create client pointer */ output.len = i;
cp = clnt_create(serverName, CRESAR, VERSION, “udp”); return &output; /* return result */
if (cp == NULL) exit(1); }
arg.key = 1; /* set RPC parameters */
arg.cipher = “Buubdl!bu!ebxo”; Data* encrypt_2(args *a){ /* encryption */
plaintext = decrypt_2(&arg, cp); /* issue RPC */ /* … */
}
/* other processing */

clnt_destroy(cp); /* delete client pointer */
}

Distributed Systems 40
Example: SUN RPC(4)

Server program Server code

Server stub

RPC
XDR Definition Header file
library

client stub
Client program Client code

The steps in writing a client and a server in SUN RPC

Distributed Systems 41
The steps in writing a client and a server in DCE
RPC

IDL: Interface Definition Language; uuidgen: IDL file generator


DCE: Distributed Computing Environment (Open Software foundation)
Distributed Systems 42
RPC Semantics

LPC has exact-once semantics, how about RPC?


Server dead? RPC request lost? Reply lost?
 Re-sending RPC (time out)
 Replica filtering
 Re-sending results
Re-sending RPC Replica filtering Re-sending results RPC semantics

no no no maybe
yes no no at-least-once
yes yes no maybe-once
yes yes yes at-most-once

Distributed Systems 43
RMI: Remote Method Invocation

Distributed Systems 44

Vous aimerez peut-être aussi