Unit - 2 Common Presentation
Unit - 2 Common Presentation
Ordering
UNIT - 2
BYTE ORDERING
• An arrangement of bytes when data is transmitted over
the network is called byte ordering.
• Different computers will use different byte ordering.
• When communication taking place between two machines
byte ordering should not make discomfort.
• Generally an Internet protocol will specify a common form
to allow different machines byte ordering. TCP/IP is the
Internet Protocol in use.
• Two ways to store bytes : Big endian and little endian
Big-endian
• High order byte is stored on starting address and low
order byte is stored on next address
Little-endian
• Low order byte is stored on starting address and high
order byte is stored on next address
Byte ordering functions
• Special functions are applied through routines to convert host’s
internal byte order representation to network byte order.
unsigned short htons()
• This function converts 16-bit (2-byte) data from host byte order to
network byte order.
unsigned long htonl()
• This function converts 32-bit (4-byte) data from host byte order to
network byte order.
unsigned short ntohs()
Byte Ordering Functions • This function converts 16-bit (2-byte) data from network byte order to
host byte order.
unsigned long ntohl()
• This function converts 32-bit (4- byte) data from network byte order to
host byte order.
SYSTEM CALLS & SOCKETS
System calls
• System Calls – An interface between process and operating systems.
It provides
• The services of the operating system to the user programs via Application Program
Interface(API).
• An interface to allow user-level processes to request services of the operating system.
• System calls are the only entry points into the kernel system.
SYSTEM CALLS & SOCKETS
Sockets
• Socket is an interface between applications and the network
services provided by operating systems.
APPLICATION
In UNIX systems, socket is just a special file, and socket descriptors are kept in the file descriptor
table.
The Windows operating system keeps a separate table of socket descriptors (named socket
descriptor table, or SDT) for each process.
Socket creation
• The socket API contains a function socket() that can be called to create a socket.
Types of Sockets
Under protocol family AF_INET
○ Stream socket
■ Uses TCP for connection-oriented reliable communication
■ Identified by SOCK_STREAM
■ s = socket(AF_INET, SOCK_STREAM, 0) ;
○ Datagram socket
■ Uses UDP for connectionless communication
■ Identified by SOCK_DGRAM
■ s = socket(AF_INET, SOCK_DGRAM, 0) ;
○ RAW socket
■ Uses IP directly
■ Identified by SOCK_RAW
System Data Structures for Sockets
● When an application process calls socket(), the operating system allocates a
new data structure to hold the information needed for communication,
and fills in a new entry in the process’s socket descriptor table (SDT) with a
pointer to the data structure.
● A process may use multiple sockets at the same time. The socket descriptor
table is used to manage the sockets for this process.
Data Structure for Sockets ● The internal data structure for a socket contains many fields, but the
system leaves most of them unfilled. The application must make additional
procedure calls to fill in the socket data structure before the socket can be
used.
● The socket is used for data communication between two processes (which
may locate at different machines). So the socket data structure should at
least contain the address information, e.g., IP addresses, port numbers, etc.
Functions used in client program
Receiving data
• read(int sockfd, void *buf, size_t len)
• Arguments: socket descriptor, pointer to buffer to place the data, size of the buffer
• Returns the number of characters read (where 0 implies “end of file”), and -1 on error
● RPC allows programs to call the procedure which is located on the other
machines.
● RPC enables a procedure call that does not reside in the address space of
the calling process.
● In RPC, the caller and the callee has disjoint address space, hence there is no
access to data and variables in the callers environment.
● A client has a request message that the RPC translates and sends to the server.
● When the server receives the request, it sends the required response back to the client.
● The client is blocked while the server is processing the call and only resumed execution
after the server is finished.
Client Server RPC Model
Sequence of events in a RPC
● The client stub is called by the client.
● The client stub makes a system call to send the message to the server
and puts the parameters in the message.
● The message is sent from the client to the server by the client’s
operating system.
● The parameters are removed from the message by the server stub.
23
Marshalling
• The process of transforming the memory
representation of an object into a data format
suitable for storage or transmission.
24
RPC Features
● Remote procedure calls support process oriented and thread oriented models.
● The internal message passing mechanism of RPC is hidden from the user.
● The effort to re-write and re-develop the code is minimum in remote procedure calls.
● Remote procedure calls can be used in distributed environment as well as the local environment.
• An iterative server
• Iterates through each client, handling it one at
a time.
• A concurrent server
• Handles multiple clients at the same time.
27
• The function fork() is called once but returns
twice.
29
30
Example of interaction among a client and a concurrent server
Iterative Server
• An iterative server handles both the connection
request and the transaction involved in the call
itself.
TCP package
TCP Package
●TCP is a stream-service, connection-oriented
protocol with an involved state transition
diagram.
●It uses flow and error control.
●It is so complex because actual code includes
tens of thousands of lines.
Transmission Control Blocks (TCBs)
• TCP is a connection-oriented transport protocol.
• A connection may be open for a long period of time.
• To control the connection, TCP uses a structure to hold information
about each connection.
Timers
• TCP needs to keep track of its operations.
• Three software modules
Main module
An input processing module
An output processing module
TCP Package acknowledgments and decides to take a time out and stop
sending altogether.
PTO is the maximum idle time between the completion of a
TCP transaction and the initiation of a new TCP transaction.
Limitations of UDP
● There is no flow control mechanism.
Cannot send a stream of data to UDP, It will chop them into different
packets related user datagrams.
UDP Services
Flow control
Congestion control
Does not provide congestion control and has an assumption that the packets are small and
Pseudo header
It is a part of the IP header
Encapsulated with some fields with 0’s
Protocol field to differentiate between UDP and TCP
The value of the protocol field is 17. If it is changed
then the packet gets discarded at receiver end.
• The client process can send messages to the outgoing queue by using
the source port number specified in the request
The client process can send messages to the outgoing queue by using the source port number
specified in the request
UDP removes the messages one by one and, after adding the UDP header, delivers them to IP. An
outgoing queue can overflow
It happens the operating system can ask the client process to wait before sending any more
messages
Demultiplexing
One to many relationship.
UDP receives the user datagram from IP and drops the
header then sends the message to appropriate process based
on port numbers.
UDP Features
Connectionless services
Lack of error control
Lack of congestion control
Connectionless service
Preferable for small message which fits in a single datagram.
The overhead to establish and close a connection may be significant whereas in TCP it
takes 9 packets for exchanges between client and server to achieve the above goal.
In reliable service the transport layer needs to take care of the lost packet by resending
it. So there will be a uneven delay between different parts of the message delivered.
Lack of congestion control
UDP design
Input Queues
UDP package uses a set of input queues, one
for each process. In this design, we do not
use output queues.
Mrs.B.Ida Seraphim AP/CSE
UDP Package
Control-Block Module
The control-block module is responsible for the
management of the control-block table.
Output module
• The output module is responsible for creating and sending
user datagrams.
SCTP is a message-oriented, reliable protocol that combines the best features of UDP and TCP.
Difference between SCTP, TCP and UDP
SCTP Services
• Process-to-Process Communication
• Multiple Streams
• Multihoming
• Full-Duplex Communication
• Connection-Oriented Service
• Reliable Service
SCTP Services
Process-to-Process Communication
• SCTP uses all well-known ports in the TCP space
Some SCTP applications • The problem with this approach is that a loss at
any point in the stream blocks the delivery of the
rest of the data.
Multiple-stream concept
Multiple-stream concept
Full-Duplex Communication
Reliable Service
• It uses an acknowledgment mechanism to check the safe and sound arrival of data.
SCTP FEATURES
Packets
• Data are carried as data chunks, control information as control
Packet, data chunks, and streams chunks.
• Several control chunks and data chunks can be packed together in a
packet.
SCTP Features
Comparison between a TCP segment and an SCTP packet
Flow Control
• SCTP implements flow control to avoid overwhelming receiver
Error Control
• TSN numbers and acknowledgment numbers are used for error control.
Congestion Control
• SCTP implements congestion control to determine how many data chunks can be injected into the
network
SCTP Features
Types of chunks
• Control chunks - controls and maintains the association
• Data chunks - carries user data
SCTP packet format
SCTP Packet Format
General Header
• Defines the end points of each association to which the
packet belongs.
• Guarantees for a packet belongs to a particular association.
• Preserves the integrity of the contents of the packet.
There are four fields in the general header
• Source port address: 16-bit field defines the port number
of the sender process
General header • Destination port address: 16-bit field defines the port
number of the receiving process
• Verification tag: Number that matches a packet to an
association
• It serves as an identifier for the association
• Separate verification used for each direction in the
association.
• Checksum: 32-bit field contains a CRC-32 checksum
SCTP Packet Format
Chunks
• Control information or user data are carried
• First three fields are common to all chunks
• Type: 8-bit field define up to 256 types of chunks(few
have been defined, rest are reserved for future use)
• Flag: 8-bit field defines special flags that a particular chunk
may need.
• Length: 16-bit field defines the total size of the chunk, in
Types of Chunks
bytes, including the type, flag, and length fields
• TSN - Sequence number initialized in an INIT chunk for one direction and in the INIT
ACK chunk for the opposite direction
DATA chunk • SI - all chunks of same stream in one direction have same stream identifier
• Protocol identifier: 32-bit field used by the application program to define the type of
data which is ignored by SCTP
INIT chunk
SCTP Packet Format
INIT ack(initiation acknowledgment chunk)
• Second chunk sent during association establishment
• Value of the verification tag is the value of the initiation tag of INIT
chunk.
• The parameter of type 7 defines the state cookie sent by the sender of
this chunk
INIT ACK
chunk • Initiation tag field in this chunk initiates the value of the
verification tag for future packets traveling from the opposite
direction.
SCTP Packet Format
Cookie echo
• Third chunk sent during association establishment that carry
user data too.
• Sent by the end point that receives an INIT ACK chunk.
COOKIE ECHO chunk • Chunk of type 10.
COOKIE ACK
• fourth and last chunk sent during association establishment
with data chunk too.
COOKIE ACK • sent by an end point that receives a COOKIE ECHO chunk.
• chunk of type 11.
SCTP Packet Format
SACK(selective ACK chunk)
• Acknowledges the receipt of data packets
• Common fields
• Type field has 3
• Flag bits are set to 0s
• Cumulative tsn acknowledgment: 32-bit field defines the tsn of the last data chunk
received in sequence
• Advertised receiver window credit: 32-bit field that have updated value for the receiver
window size
• Number of gap ACK blocks: 16-bit field defines the number of gaps in the data chunk
received after the cumulative
TSN
• Number of duplicates: 16-bit field defines the number of duplicate chunks following the
SACK chunk cumulative TSN
• Gap ACK block start offset: 16-bit field gives the starting TSN relative to the cumulative
TSN
• Gap ACK block end offset: 16-bit field gives the ending TSN relative to the cumulative TSN
• Duplicate tsn: 32-bit field gives the tsn of the duplicate chunk.
SCTP Packet Format
HEARTBEAT and HEARTBEAT ACK
• First has a type of 4 and the second a type of 5
• Used to periodically probe the condition of an association
• An end point sends a HEARTBEAT chunk, peer responds HEARTBEAT ACK if it is
alive
HEARTBEAT and HEARTBEAT ACK chunks • Parameter fields provide sender-specific information like address and local time
• Same is copied into the HEARTBEAT ACK chunk.
ERROR
• Sent when an end point finds some error in a received packet.
• It does not imply the aborting of the association.
ABORT
• Sent when an end point finds a fatal error and needs to abort the
Errors association.
FORWARD TSN
ERROR chunk
• This is a chunk recently added to the standard to inform the
receiver to adjust its cumulative TSN
ABORT chunk
SCTP Client/Server(Association)
Association Establishment
• Four-way handshake
1. First packet has INIT chunk sent by client
• Verification tag is 0
• Rwnd is advertised in a SACK chunk
• Inclusion of a DATA chunk in the third and fourth
packets
2. Second packet has INIT ACK chunk sent by server
• Verification tag is the initial tag field in the INIT chunk
• Initiates the tag to be used in the other direction
• Defines the initial TSN and sets the servers’ rwnd
3. Third packet has COOKIE ECHO chunk sent by client
• Echoes the cookie sent by the server
Four-way handshaking • Data chunks are included in this packet
4. Fourth packet has COOKIE ACK chunk sent by server
• Acknowledges the receipt of the COOKIE ECHO chunk
• Data chunks are included with this packet.
SCTP Client/Server(Association)
Number of Packets Exchanged
• Number of packets exchanged is four(3 for TCP)
• Allows the exchange of data in the third and fourth packets, so it is efficient
Verification tag
• It is a common value carried in all packets traveling in one direction in an association
• Blind attacker cannot inject a random packet into an association
• A packet from an old association cannot show up in an incarnation
Cookie
• Cookie is sent with the second packet to the address received in the first packet
• If the sender of the first packet is an attacker, the server never receives the third packet
• If the sender of the first packet is an honest client, it receives the second packet, with the cookie
SCTP Client/Server(Association)
Data transfer
• Purpose of an association is to transfer data between two ends.
• Each message coming from the process is treated as one unit and
inserted into a DATA chunk.
Multistream delivery
• TSN numbers are used to handle data transfer whereas delivery of the data chunks are controlled by
SIs and SSNs.
• Two types of data delivery in each stream
• Ordered: SSNs define the order of data chunks in the stream.
• Unordered: U flag is set, it delivers the message carrying the chunk to the
destination application without waiting for the other messages.
SCTP Client/Server(Association)
Fragmentation
• SCTP preserves the boundaries of the message when creating DATA chunk from a message
• If the total size exceeds the MTU, the message needs to be fragmented
• If not, the data in the queue are sent and the association
Association termination
is closed
• Server may wish to abort since it has received an INIT chunk with
wrong parameters, requested resources are not available after
Association abortion
receiving the cookie, the operating system needs to shut down etc.
• For abortion process either end can send an abort chunk to abort the
association