Transcript topic 2x

Topic 2: Interposes
Communication
Dr. Ayman Srour
Faculty of Applied Engineering and Urban Planning
University of Palestine
2.1 Overview of Network
Principles
• The networks in the distributed systems are built
from a variety of transmission media, hardware
devices and software components
• transmission media: including wire, cable, fibre
and wireless channel.
• hardware devices: including routers, switches,
bridges, hubs, etc.
• software components: including protocol stacks,
communication handlers and drivers.
• The characteristics of such networks impact the
performance and behaviour of a distributed
system.
2.1 Overview of Network
Principles
• communication subsystem: is a collection of hardware and
software components that provide the communication
facilities for a distributed system.
• Hosts: the computers and other devices that use the network
for communicate purposes.
• Node: any computer or switching device attached to a
network.
• E.g., the Internet is a single communication subsystem
providing communication between all of the hosts that are
connected to it.
• We need to have some understanding of such principles in
order to evaluate the effect of network characteristics on the
distributed system’s performance, scalability, reliability,
security and mobility.
2.1 Overview of Network
Principles
• Performance: concern with the factors that affecting the speed messages transition
between two interconnected computers, including latency and Data transfer rate.
• Scalability: The potential future size of the Internet is commensurate with the
population of the planet. It is realistic to expect it to include several billion nodes and
hundreds of millions of active hosts.
• Reliability: the ability to detect and recover communication errors. Usually occurs in
the application-level software.
• Security: it is necessary enable distributed applications to move beyond the
restrictions imposed by firewalls there is a need to produce a secure network
environment in which a wide range of distributed applications can be deployed
with end-to-end authentication, privacy and security.
• Mobility: Mobile devices such as laptop computers and Internet-capable mobile
phones are moved frequently between locations and reconnected at convenient
network connection points or even used while on the move.
2.1 Overview of Network
Principles
Types of Networks:
o Local Area Networks (LANs):
• LANs support the exchange of messages at relatively high
speeds between computers connected by a single
communication medium.
• A segment is a section of a cable that can connect many
computers in ,e.g., a building.
• No routing is required in a segment.
•
Larger LANs can be constructed by connecting more that one
segment using a hub.
• LANs can be implemented using the Ethernet, Token Rings.
2.1 Overview of Network
Principles
Types of Networks:
o Metropolitan Area Networks (MANs):
• Based on the high bandwidth copper and fibre optic
cables which are installed across towns and cities.
• Can be implemented in many technologies ranging from
the Ethernet to ATM.
o Wireless Networks:
• Supports mobile terminals.
• Examples include: WLANs, WPANs, GSM.
2.1 Layered Protocols
 Protocols:
•
•
•
•
•
Communications in distributed systems is based on message
exchange.
To resolve the numerous issues & levels involved in communication,
the Open Systems Interconnection (OSI) model is developed.
The OSI is designed to allow open systems to interconnect &
communicate.
An open system is one that is prepared to communicate with any
other open systems by using standard rules that govern the format,
contents, and meanings of messages sent or received.
These rules are called protocols.
2.1 Layered Protocols
 Protocols:
•
•
•
protocol is a set of rules to communicate between processes to perform a task.
A protocol contains a specification of a set of messages and their contents.
Network protocols are arranged into layers, where each layer acts as an interface
to the layer above it with the latter extending the network properties
• Generally there are 2 types of protocols
• Connection-oriented: in which a “virtual connection” is set up between a
sending and receiving process and is used for the transmission of a stream of
data. Sequencing and acknowledgement are included.
• Connectionless : which individual messages, known as datagrams, are
transmitted to specified destinations. No sequencing or acknowledgement
•
The OSI model divides communication into 7 layers.
2.1 Layered Protocols
2.1 Layered Protocols
 Protocols:
•
•
•
•
Application layer: Protocols that are designed to meet the
communication requirements of specific applications, often defining
the interface to a service. (HTTP, FTP, Telnet, SMTP, CORBA IIOP).
Presentation layer: Protocols at this level transmit data in a network
representation that is independent of the representations used in
individual computers. Encryption is performed in this layer if needed.
(XDR, CORBA Data Representation, encryption).
Session layer: At this level communication between processes is
established and error recovery is performed. It is not required for
connectionless communication.
Transport layer: This is the lowest level at which messages (rather than
packets) are handled. Messages are addressed to communication
ports. This layer also constructs an end-to-end reliable connectionoriented channel between two parties. Its tasks include flow control,
error detection and correction and sequencing (TCP).
2.1 Layered Protocols
 Protocols:
•
•
•
Network layer: Transfers data packets between computers in
a specific network. Also concerned with the use of
networking to create channels needed for communication.
Routing is delt with in this layer (IP).
Data link layer: responsible for error-free transmission of
packets between nodes that are directly linked by a physical
connection, i.e. between pairs of routers.
Physical layer: The circuits and hardware that drives the
network (Bit transmission using proper communication
medium.
2.1 Layered Protocols
 Protocols:
•
The Internet protocol suite (I.e., a complete set of
protocol layers) provides two types of transport-layer
service:
• TCP is a connection-oriented service that transmits streams of
bytes across a pre-established connection
• UDP is a connectionless service that transmits messages of up to
64 kilobytes to a specified destination (a communication
identifier which is IP address + port number).
2.1 Layered Protocols
 Routing:
•
•
•
•
•
Routing in a network is required when there is no direct link
between nodes.
Routers at connection points of such network cooperate to
deliver packets from source to destination.
Packets are transmitted through a number of hops between
routers.
A routing algorithm is used in each of the routers and
implemented as a program in the network layer.
A routing algorithm make decisions regarding the path that
each packet has to go through in the network.
2.1 Layered Protocols
 Internet Protocols:
•
•
•
•
•
•
•
IP is a network protocol providing basic transmission mechanism for
the Internet.
is usually based on another network protocol specific to subnet (e.g.
the Ethernet).
Transmits datagrams between hosts via routers if necessary.
The IP protocol provides an unreliable (best-offer) service as there is
no guarantee of delivery.
The only error-detection mechanism used in IP is a header checksum
which detect whether the header was corrupted during transmission.
The IP protocol implements part of the Network layer. IP datagrams
are then put in packets suitable for transmission in the underlying
network (e.g. Ethernet).
Routing is the responsibility of the IP protocol from source to
destination.
2.1 Layered Protocols
 TCP/IP Protocol Layers
2.1 Layered Protocols
 TCP Protocol:
•
A transport layer protocol that support process-to-process
communication.
•
Ports are used to address messages to specific processes in
communicating hosts.
TCP provides a connection-oriented reliable service where a guarantee
is provided to deliver messages in the same order.
Communicating processes, at the start of communication agree on
establishing an end-to-end reliable connection.
The network, e.g. the routers have no knowledge of such connection
agreement.
IP packets carrying the TCP part don’t necessarily follow the same
route in the network.
•
•
•
•
2.1 Layered Protocols
 TCP Protocol:
•
•
Several reliability mechanisms are supported in TCP including:
o
Sequencing: divide the data to be communicated into a sequence of data segments and
transmit them as IP packets. The receiver uses the sequence number to order the received
segments to re-construct the data stream which is then presented to the receiving process.
o
Flow Control: Aims to control the rate at which segments (packets) are communicated. A
segment acknowledgment mechanism is used. From time to time, the receiver informs the
transmitter of the highest sequence number received together with a window size.
o
Retransmission: If any segment is not acknowledged within a specified timeout, the sender
retransmit that segment.
o
Buffering: The incoming buffer at the receiver is used to balance the difference in flow
between the sender and receiver.
o
Checksum: Each segment includes a checksum covering the header and the data. If a received
segment does not match its checksum, retransmission is performed.
UDP is another transport layer protocol that does not provide the reliability
mechanisms reviewed above (except checksums).
2.2 Interprocess Communication
 Introduction:
•
TCP (and UDP) protocols provide a mean for processes at different
hosts to communicate through the exchange of
•
We have discussed the TCP protocol (and UDP) without describing
how a distributed application can use such protocols.
•
The Java programming language provides an API to implement
these protocols.
•
Before considering the programming aspects, we need to describe
the characteristics of interprocess communication.
2.2 Interprocess Communication
 Introduction:
•
2.2 Interprocess Communication
 Interprocess Communication Characteristics:
•
Message passing between two processes can be supported
through two operations send and receive:
o
One process makes a send operation to send a message.
o The destination process must support a receive operation to receive the message.
•
Characteristics include:
o Synchronous VS. asynchronous.
o Addressing/Message destinations.
o Reliability.
o Ordering.
2.2 Interprocess Communication
 Interprocess Communication Characteristics:
•
Synchronous and asynchronous communication:
o A queue is associated with each message destination.
o Sending processes cause messages to be added to remote queues and
receiving processes remove messages from local queues.
o synchronous
communication: the sending and receiving processes
synchronize at every message. Whenever a send is issued the sending process
(or thread) is blocked until the corresponding receive is issued. Whenever a
receive is issued by a process (or thread), it blocks until a message arrives.
o asynchronous communication: the use of the send operation is non-blocking
in that the sending process is allowed to proceed as soon as the message has
been copied to a local buffer, and the transmission of the message proceeds
in parallel with the sending process. The receive operation can have blocking
and non-blocking variants.
2.2 Interprocess Communication
 Interprocess Communication Characteristics:
•
Addressing/Message destinations:
o
Messages are sent to (Internet address, local port) pairs.
o A local port is a message destination within a computer, specified as an integer. A
port has exactly one receiver but can have many senders.
o Any process that knows the number of a port can send a message to it.
o Servers generally publicize their port numbers for use by clients.
2.2 Interprocess Communication
 Interprocess Communication Characteristics:
•
Reliability:
o Defines reliable communication in terms of validity and integrity
o a point-to-point message service can be described as reliable if messages are
guaranteed to be delivered despite a ‘reasonable’ number of packets being
dropped or lost.
o In contrast, a point-to-point message service can be described as unreliable if
messages are not guaranteed to be delivered in the face of even a single packet
dropped or lost.
•
Ordering :
o
Some applications require that messages be delivered in sender order -that is, the
order in which they were transmitted by the sender
o The delivery of messages out of sender order is regarded as a failure by such
applications.
2.2 Interprocess Communication
 sockets:
•
•
•
•
•
•
•
Sockets represent the endpoints of communication in TCP or UDP.
For an intercommunication to occur between two processes, a
message is transmitted between the socket of one process to the
socket of the other process (as illustrated in the figure on the next
slide).
A computer has a large number of possible port numbers which can be
used by local processes to receive messages.
The socket of the receiving process must be bound to a local port and
an IP address of the computer on which the process is running.
A process can use multiple ports to receive messages but different
processes cannot share one port.
A process can use the same socket for sending and receiving.
Each socket can only provide support for one protocol (TCP or UDP).
2.2 Interprocess Communication
2.2 Interprocess Communication
 sockets:
•
Java API for Internet addresses: Java provides a class, InetAddress,
that represents Internet addresses.
•
By using this class user can refer to computers by DNS hostname .
•
For example, to get an object representing the Internet address of
the host whose DNS name is bruno.dcs.qmul.ac.uk, use:
•
This method can throw an UnknownHostException.
2.2 Interprocess Communication
 UDP datagram communication:
•
A datagram sent by UDP is transmitted from a sending process to a
receiving process without acknowledgement or retries.
•
To send or receive messages a process must first create a socket
bound to an Internet address of the local host and a local port.
•
A server will bind its socket to a server port – one that it makes
known to clients so that they can send messages to it.
•
A client binds its socket to any free local port.
•
The receive method returns the Internet address and port of the
sender, allowing the recipient to send a reply.
2.2 Interprocess Communication
 UDP datagram Communication:
•
Message size: The receiving process needs to specify an array of
bytes of a particular size in which to receive a message.
•
Blocking: Sockets normally provide non-blocking sends and
blocking receives for datagram communication (a non-blocking
receive is an option in some implementations).
•
Timeouts: in case of receive blocks , it is not appropriate that a
process that has invoked a receive operation should wait
indefinitely in situations where the sending process may have
crashed or the expected message may have been lost.
•
Receive from any: the receive method does not specify an origin
for messages. Instead, an invocation of receive gets a message
addressed to its socket from any origin.
2.2 Interprocess Communication
 UDP Interprocess Communication
Implementation :
•
•
The Java API for UDP datagram communication is provided in the
classes DatagramPacket and DatagramSocket. included in the java.net
package.
DatagramPacket class:
o This class provides a constructor that makes an instance out of an array of bytes
comprising a message, the length of the message and the Internet address and local
port number of the destination socket .
o This class provides another constructor for use when receiving a message.
o A received message is put in the DatagramPacket together with its length and the
Internet address and port of the sending socket.
o Include methods like: getData, getPort and getAddress; .
2.2 Interprocess Communication
 UDP Interprocess Communication
Implementation :
•
DatagramSocket class:
o This class supports sockets for sending and receiving UDP datagrams. It provides a
constructor that takes a port number as its argument, for use by processes that need to
use a particular port.
o It also provides a no-argument constructor that allows the system to choose a free local
port.
o send and receive methods: These methods are for transmitting datagrams between a
pairof sockets. The argument of send is an instance of DatagramPacket containing a
message and its destination. The argument of receive is an empty DatagramPacket in
which to put the message, its length and its origin.
o setSoTimeout method : This method allows a timeout to be set. With a timeout set, the
receive method will block for the time specified and then throw an
InterruptedIOException.
o Connect method: This method is used for connecting to a particular remote port and
Internet address, in which case the socket is only able to send messages to and receive
messages from that address.
2.2 Interprocess Communication
2.2 Interprocess Communication
2.2 Interprocess Communication
 TCP Interprocess Communication
Implementation :
•
•
The Java API for TCP stream implementation is provided in the classes
ServerSockets and Socket. included in the java.net package.
ServerSocket class:
o Used by the server to create a socket and associate it with a port.
o The socket listens for connect requests from clients.
o The class’s accept method get a request from the queue, or blocks if the queue is empty.
o The result of executing accept is an instance of Socket which provides access to streams
for communication with client
•
Socket class:
o Its constructor is used by the client to create a socket specifying DNS hostname and port
number of the server. The newly created socket is connected with the remote computer.
o UnknownHostException is thrown by the constructor if the hostname is not recognised.
o IOException is raised if an IO error occurs.
2.2 Interprocess Communication
2.2 Interprocess Communication
2.2 Interprocess Communication