Unit 2
Unit 2
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
APPLICATION network services provided by operating systems.
SOCKET – APPICATION INTERFACE(API) • Applications use sockets to send and receive the data.
TCP/IPV4, TCP/IPV6, UNIX
• Socket provides IP address and port address
Socket Descriptors
To perform file I/O, file descriptor is used.
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.
defning a Socket as : SOCKET( DOMAIN , TYPE , PROTOCOL )
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
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.
● 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
● 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 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.
TCP package
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.
• This is called a transmission control block (TCB).
Fields in TCB
✔ State Local window Buffer size
✔ Process Remote window Buffer pointer
✔ Local IP address Sending sequence number
TCBs ✔ Local port number Receiving sequence number
✔ Remote IP address Sending ACK number
✔ Remote port number Round-trip time
✔ Interface Time-out values
TCP Package
Timers
• TCP needs to keep track of its operations.
• Three software modules
✔ Main module
✔ An input processing module
✔ An output processing module
Input Processing Module
• The Input processing module handles all the details which is required for
the processing of data or an acknowledgement received when TCP is in
the ESTABLISHED STATE.
• This module sends an ACK if needed.
• Takes care of the window size
• Performs Error checking and so on.
TCP Package
Output Processing Module
✔ Located between application layer and network layer in the TCP/IP protocol suite
Connectionless services
Congestion control
Does not provide congestion control and has an assumption that the packets are small and
sporadic so they cant create congestion.
Checksum
UDP Services • Three sections: a pseudo header, the UDP header,
and the data coming from the application layer.
Pseudo header
▪ It is a part of the IP header
UDP header
Pseudo header for checksum
Data
calculation ▪ communication from the application layer
UDP Services
Encapsulation and Decapsulation
Encapsulation
• A process send message through UDP
• Along with a pair of socket address and the length of data.
• UDP receives data and add UDP header then pass to IP with socket.
• IP add its own header using value 17 in protocol field.
• Indicating UDP protocol.
• The IP datagram is then passed to the data link layer.
• The data link layer receives the IP datagram and passes it to the physical layer.
• The physical layer encodes the bits into electrical or optical signals and sends it to
the remote machine.
Decapsulation
Queuing in UDP
• The client process can send messages to the outgoing queue
by using the source port number specified in the request
Mrs.B.Ida Seraphim AP/CSE
Queuing in UDP
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
Input Queues
UDP design
UDP package uses a set of input queues, one for
each process. In this design, we do not use output
queues.
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.
SCTP Services
Process-to-Process Communication
• SCTP uses all well-known ports in the TCP space
• If one of the streams is blocked, the other streams can still deliver
their data
Multiple-stream concept
SCTP ServicesMultihoming
• The sending and receiving host can define multiple IP addresses in
each end for an association.
• when one path fails, another interface can be used for data delivery
without interruption.
Multihoming concept • This fault-tolerant feature helps in sending and receiving a real-time
payload such as Internet telephony.
Full-Duplex Communication
• SCTP has sending and receiving buffer, hence packets are sent in both
directions.
SCTP Services
Connection-Oriented Service
• A connection is called an association in SCTP
• Steps to send and receive data in SCTP
1. The two SCTP’s establish an association between each other.
2. Data are exchanged in both directions.
3. The association is terminated.
Reliable Service
• It uses an acknowledgment mechanism to check the safe and sound arrival of data.
SCTP Services
Transmission Sequence Number (TSN)
• Unit of data in SCTP is called the data chunk.
• Data transfer in SCTP is controlled by numbering the data chunks.
• SCTP uses a TSN to number the data chunks with 32 bits long number which is randomly initialized
between 0 and 232− 1.
• Each data chunk carry their TSN in its header.
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
• Destination port address: 16-bit field defines the port
number of the receiving process
General header
• 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
DATA INIT ACK chunk for the opposite direction
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 cumulative TSN
SACK chunk • 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
• Parameter fields provide sender-specific information like address and local time
HEARTBEAT and HEARTBEAT ACK
chunks
• Same is copied into the HEARTBEAT ACK chunk.
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.
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
Association abortion
• Server may wish to abort since it has received an INIT
chunk with wrong parameters, requested resources
are not available after receiving the cookie, the
operating system needs to shut down etc.